windows customscriptextension fails - terraform

"commandToExecute": "powershell.exe -executionpolicy Unrestricted -File "./Add-WVDHostToHostpoolSpringORG4T.ps1" "
fails with the below error
Error: Code="VMExtensionProvisioningError" Message="VM has reported a failure when processing extension 'CustomScriptExtension'. Error message: "Command execution finished, but failed because it returned a non-zero exit code of: '1'. The command had an error output of: 'At \r\nC:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.10.12\Downloads\0\Add-WVDHostToHostpoolSpringORG4T.ps1:1 \r\nchar:1\r\n+ <#\r\n+ ~~\r\nThe terminator '#>' is missing from the multiline comment.\r\n + CategoryInfo : ParserError: (:) [],...' For more information, check the instance view by executing Get-AzVmssVm or Get-AzVm (https://aka.ms/GetAzVm). These commands can be executed using CloudShell (https://aka.ms/CloudShell)"\r\n\r\nMore information on troubleshooting is available at https://aka.ms/VMExtensionCSEWindowsTroubleshoot "
│

• I would suggest you to please try executing the powershell script on a separate test VM first to ensure that the desired results are being achieved through the script. Also, would suggest you to please refer the below community thread for the appropriate usage of parameters to be used in custom script extension while deploying powershell script through it.
Install applications or software on Azure VM with ARM Template
Also, according to the error that you have encountered, it seems that you have missed adding a ‘#’ mark before as a prefix to the supposed comment remark in the script due to which the powershell script when executed is giving out an error stating the same. Or else that you might have added an extra ‘#’ mark before a supposed legit powershell command in the script due to which the script didn’t get executed and is giving out this error.
Kindly refer the below community thread also for more details into this: -
powershell is missing the terminator: "

Related

mutipass:launch failed: Failed to resize instance image - error executing powershell command

I always have the following error when I install a virtual machine
launch failed: Failed to resize instance image - error executing powershell command. Detail: Resize-VHD : �޷������������̵Ĵ�С��
ϵͳ�޷�������C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\multipassd\vault\instances\krun\ubuntu-20.04-serv
er-cloudimg-amd64.vhdx���Ĵ�С��
�޷������������̵Ĵ�С��
ϵͳ�޷�������C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\multipassd\vault\instances\krun\ubuntu-20.04-serv
er-cloudimg-amd64.vhdx���Ĵ�С: ��һ����������ʹ�ô��ļ��������޷����ʡ� (0x80070020)��
����λ�� ��:1 �ַ�: 1
Resize-VHD -Path C:/WINDOWS/system32/config/systemprofile/AppData/Roa ...
+ CategoryInfo : ResourceBusy: (:) [Resize-VHD], VirtualizationException
+ FullyQualifiedErrorId : ObjectInUse,Microsoft.Vhd.PowerShell.Cmdlets.ResizeVhd
Background
In my case, I changed the location of my multipass instance locations by following this post here. I then created a folder on my drive where I wanted the instances to be stored.
After doing so, multipass launch failed with your exact same error. After trying reboots, uninstall/reinstall multipass, etc. - I finally tried renaming the folder where I wanted to store my multipass instances, and this worked.
Apparently, if your destination multipass folder includes a space, some part of the script fails.
Workaround / Fix
When specifying a multipass instance destination:
MULTIPASS_STORAGE -Value "<path>"
Make sure there are NO SPACES in the "<path>" you have provided.
Hope this helps.
You have to add the HyperV module to powershell in "Turn Windows features on or off", if you don't check this the checkbox, "Resize-VHD" won't work and will fail the multipass launch.
The direct command is:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell

"An error occurred while creating the pipeline." when running powershell script in Azure pipeline self-hosted agent

When I run simple powershell with only ls command in it through Azure pipeline self-hosted agent I see error:
An error occurred while creating the pipeline.
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RuntimeException
The same script runs fine locally in the same folder on the same machine (when no Azure agent is involved). The pipeline has not been changed in months.
The execution policy is set to "Unrestricted".
There is no difference whether the agent is run with admin permissions.
I checked and the files in the folders of the agent do not look blocked or read-only.
We run tests through powershell scripts and they started to fail last week, without any obvious reason. The only thing that I have installed on the same machine, is Visual Studio 2022 Preview 5, but I have restarted the machine immediately after the installation has passed successfully and the next day the tests have passed.
I had a look through similar errors here, in stackoverflow, but they were not useful, including this one PowerShell "an error occurred while creating the pipeline" #Requires -Version 3.0
Do you have an idea what can cause this?
The PowerShell scripts started passing when I changed the Azure Powershell pipeline task version from 1* to 2* (the latest available for our pipelines).
I do not know why this fixed the issue, as I think the difference between these 2 version is that version 2* can be executed on agents that have operating system that is not Windows.

Powershell Unable to find type [Pester.OutputTypes] on VSCode Linux

I'm working on a powershell port of Lesspass using Visual Studio Code on Linux Mint.
Test were working nicely from the IDE as of today.
From VSCode
Now When I'm on a test file and hit F5 to run the test I got:
PS ~/projects/Lesspass/Lesspass> ~/projects/Lesspass/Lesspass/src/Password.tests.ps1
Unable to find type [Pester.OutputTypes].
At ~/.local/share/powershell/Modules/Pester/4.6.0/Functions/PesterState.ps1:8 char:9
+ [Pester.OutputTypes]$Show = 'All',
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Pester.OutputTypes:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
The Describe command may only be used from a Pester test script.
At ~/.local/share/powershell/Modules/Pester/4.6.0/Functions/Describe.ps1:234 char:9
+ throw "The $CommandName command may only be used from a Peste ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (The Describe comman\u2026Pester test script.:String) [], RuntimeException
+ FullyQualifiedErrorId : The Describe command may only be used from a Pester test script.
From makefile
However when running my test with make test it works. The task is:
.PHONY: test
test:
pwsh -Command 'Invoke-Pester -EnableExit (Get-childItem -Recurse *.tests.ps1).fullname'
I think your issue is likely the fact that you are attempting to call a pester test script on it's own rather than via the Invoke-Pester Command.
I think that if you change your call to Invoke-Pester -Script ~/projects/Lesspass/Lesspass/src/Password.tests.ps1 your error may go away.
The reason is that *.tests.ps1 files do not, on their own, know how to set up all of the background plumbing required to handle a test run. Invoke-Pester does a lot of set up before test files are run, and calling a test script directly with F5 skips that setup.
If you want to be able to press F5 to kick off a test run, what many PowerShellers do in VSCode is create a debug_entry.ps1 file on the local system, and in that file put the command Invoke-Pester -Script ~/projects/Lesspass/Lesspass/src/Password.tests.ps1. Then when you want to start a run, you switch tabs to your debug_entry.ps1 file and hit F5 and your debug script makes the correct call for you. It has the side benefit of the fact that any debugging break points you have set either in the tests file, or in the code you are testing should then be respected as well.
I also think I should also point out that in your make test script, you are using Get-ChildItem to explicitly get all of the test file paths manually and pass them to Invoke-Pester. This is not necessary. Invoke-Pester by default will always search either your current working directory, or any path that you give to it recursively to find all test files available.
For instance from the output of Get-Help Invoke-Pester is the following snippet
By default, Invoke-Pester runs all *.Tests.ps1 files in the current directory
and all subdirectories recursively. You can use its parameters to select tests
by file name, test name, or tag.
This snippet from the output of Get-Help Invoke-Pester -Examples demonstrates Invoke-Pester's ability to search sub directories of a given directory, not necessarily the current working directory for tests to run
-------------------------- EXAMPLE 11 --------------------------
PS > Invoke-Pester -Script C:\Tests -Tag UnitTest, Newest -ExcludeTag Bug
This command runs *.Tests.ps1 files in C:\Tests and its subdirectories. In those
files, it runs only tests that have UnitTest or Newest tags, unless the test
also has a Bug tag.
So in your case it would probably be easier and cleaner to change your make call to
pwsh -Command 'Invoke-Pester -EnableExit
That's assuming that your build system will set the current working directory to the root folder of your project.

AWS CLI Windows Powershell command error

I am running following AWS CLI command on Windows powershell. It is reporting that I have not specified ParameterValue for ParameterKey KeyName but I have. Why is this command isn't working?
PS C:\Users\Manu> aws cloudformation create-stack --stack-name vpn --template-url https://s3.amazonaws.com/awsinaction/chapter5/vpn-cloudformation.json --para
meters ParameterKey=KeyName, ParameterValue=mykey ParameterKey=VPC, ParameterValue=$VpcId ParameterKey=Subnet, ParameterValue=$SubnetId ParameterKey=IPSecShar
edSecret, ParameterValue=$SharedSecret ParameterKey=VPNUser, ParameterValue=vpn ParameterKey=VPNPassword, ParameterValue=$Password
An error occurred (ValidationError) when calling the CreateStack operation: ParameterValue for ParameterKey KeyName is required
Powershell is having difficulty parsing that comma and thereby loses the ParameterValue afterwards. Wrap the complete section after --parameter in double-quotes, so that it would be able to resolve it.
I would still suggest you to use AWS Tools for Powershell which is far more easier to deal all these.
Hope it helps.

Import-AzurePublishSettingsFile : A positional parameter cannot be found that accepts argument 'path'

I'm newbie in using the Azure PowerShell, and I'm trying to import the AzurePublishSettingsFile using this command:
Import-AzurePublishSettingsFile C:\Users\Kulasangar G\Downloads\<SubscriptionName>-credentials.publishsettings
I'm following these steps to configure the power shell where i found this error when i tried to execute the above command:
Import-AzurePublishSettingsFile : A positional parameter cannot be found that accepts argument 'G\Downloads\Visual'.
The whole error has been pasted here.
What could be the issue? Any help would be appreciated.
Please put the path to your publish settings file in double quotes.
Import-AzurePublishSettingsFile "C:\Users\Kulasangar G\Downloads\<SubscriptionName>-credentials.publishsettings"
Because you have a space in the path, PowerShell Cmdlet is considering the path as two parameters C:\Users\Kulasangar and G\Downloads\<SubscriptionName>-credentials.publishsettings and hence the error.

Resources