CommandNotFoundException errors in Powershell script - amazon-web-services
I'm using this script to try to upload files to an S3 bucket using cURL.
#S3 parameters
$S3KEY="AKIAYZL7ANTULMU355OD"
$S3SECRET="AKIAYZL7ANTULMU355OD"
$S3BUCKET="quixel-ml-team-data"
$S3STORAGETYPE="STANDARD" #REDUCED_REDUNDANCY or STANDARD etc.
$AWSREGION="us-west-2"
file_path="C:\Users\DELL\AppData\Local\Temp\input_settings.txt"
aws_path="seam-removal\"
bucket="${S3BUCKET}"
date=$(date -R)
acl="x-amz-acl:private"
content_type="application/x-compressed-tar"
storage_type="x-amz-storage-class:${S3STORAGETYPE}"
string="PUT\n\n$content_type\n$date\n$acl\n$storage_type\n/$bucket$aws_path${file_path##/*/}"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64)
curl -s --retry 3 --retry-delay 10 -X PUT -T "$file_path" \
-H "Host: $bucket.${AWSREGION}.amazonaws.com" \
-H "Date: $date" \
-H "Content-Type: $content_type" \
-H "$storage_type" \
-H "$acl" \
-H "Authorization: AWS ${S3KEY}:$signature" \
"https://$bucket.${AWSREGION}.amazonaws.com$aws_path${file_path##/*/}"
However, I'm getting these errors. Any idea about them? Sorry, I'm a novice at this sort of programming.
file_path=C:\Users\DELL\AppData\Local\Temp\input_settings.txt : The term
'file_path=C:\Users\DELL\AppData\Local\Temp\input_settings.txt' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:11 char:1
+ file_path="C:\Users\DELL\AppData\Local\Temp\input_settings.txt"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (file_path=C:\Us...ut_settings.txt:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
aws_path=seam-removal\ : The term 'aws_path=seam-removal\' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:12 char:1
+ aws_path="seam-removal\"
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (aws_path=seam-removal\:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
bucket=${S3BUCKET} : The term 'bucket=${S3BUCKET}' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:13 char:1
+ bucket="${S3BUCKET}"
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (bucket=${S3BUCKET}:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
date=$(date -R) : The term 'date=$(date -R)' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:14 char:1
+ date=$(date -R)
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (date=$(date -R):String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
acl=x-amz-acl:private : The term 'acl=x-amz-acl:private' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:15 char:1
+ acl="x-amz-acl:private"
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (acl=x-amz-acl:private:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
content_type=application/x-compressed-tar : The term 'content_type=application/x-compressed-tar' is not recognized as
the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:16 char:1
+ content_type="application/x-compressed-tar"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (content_type=ap...-compressed-tar:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
storage_type=x-amz-storage-class:${S3STORAGETYPE} : The term 'storage_type=x-amz-storage-class:${S3STORAGETYPE}' is
not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:17 char:1
+ storage_type="x-amz-storage-class:${S3STORAGETYPE}"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (storage_type=x-...{S3STORAGETYPE}:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
string=PUT\n\n$content_type\n$date\n$acl\n$storage_type\n/$bucket$aws_path${file_path##/*/} : The module 'string=PUT'
could not be loaded. For more information, run 'Import-Module string=PUT'.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:18 char:1
+ string="PUT\n\n$content_type\n$date\n$acl\n$storage_type\n/$bucket$aw ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (string=PUT\n\n$...file_path##/*/}:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoLoadModule
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64) : The term 'signature=$(echo -en
"${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64)' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:19 char:1
+ signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (signature=$(ech...inary | base64):String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Invoke-WebRequest : Parameter cannot be processed because the parameter name 'T' is ambiguous. Possible matches
include: -TimeoutSec -TransferEncoding.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:20 char:43
+ curl -s --retry 3 --retry-delay 10 -X PUT -T "$file_path" \
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameter,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
-H : The term '-H' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:21 char:5
+ -H "Host: $bucket.${AWSREGION}.amazonaws.com" \
+ ~~
+ CategoryInfo : ObjectNotFound: (-H:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
-H : The term '-H' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:22 char:5
+ -H "Date: $date" \
+ ~~
+ CategoryInfo : ObjectNotFound: (-H:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
-H : The term '-H' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:23 char:5
+ -H "Content-Type: $content_type" \
+ ~~
+ CategoryInfo : ObjectNotFound: (-H:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
-H : The term '-H' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:24 char:5
+ -H "$storage_type" \
+ ~~
+ CategoryInfo : ObjectNotFound: (-H:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
-H : The term '-H' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:25 char:5
+ -H "$acl" \
+ ~~
+ CategoryInfo : ObjectNotFound: (-H:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
-H : The term '-H' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\DELL\Desktop\Abdullah Chand\quixel-ml-khalid-chand\script_upload_to_aws_using_curl.ps1:26 char:5
+ -H "Authorization: AWS ${S3KEY}:$signature" \
~~
CategoryInfo : ObjectNotFound: (-H:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
You're mixing a PowerShell with a traditional Unix script.
Further, there's no need to call out the external utilities like OpenSSL and Curl since PowerShell has similar capabilities built in. To sign the URL and perform the Upload without using the AWS SDK, the script would look something like this:
$method = 'PUT'
$service = 's3'
$bucket = "SAMPLES3BUCKETNAME"
$key = 'example-s3-key.txt'
$local_file = "test.txt"
$region = 'us-west-2'
$host1 = $bucket + '.s3-' + $region + '.amazonaws.com'
$access_key = 'SAMPLEACCESSKEY'
$secret_key = 'SAMPLESECRETKEY'
function HmacSHA256($message, $secret)
{
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = $secret
$signature = $hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes($message))
return $signature
}
function getSignatureKey($key, $dateStamp, $regionName, $serviceName)
{
$kSecret = [Text.Encoding]::UTF8.GetBytes(("AWS4" + $key).toCharArray())
$kDate = HmacSHA256 $dateStamp $kSecret;
$kRegion = HmacSHA256 $regionName $kDate;
$kService = HmacSHA256 $serviceName $kRegion;
$kSigning = HmacSHA256 "aws4_request" $kService;
return $kSigning
}
function hash($request)
{
$hasher = [System.Security.Cryptography.SHA256]::Create()
$content = [Text.Encoding]::UTF8.GetBytes($request)
$bytes = $hasher.ComputeHash($content)
return ($bytes|ForEach-Object ToString x2) -join ''
}
$now = [DateTime]::UtcNow
$amz_date = $now.ToString('yyyyMMddTHHmmssZ')
$datestamp = $now.ToString('yyyyMMdd')
$signed_headers = 'host'
$credential_scope = $datestamp + '/' + $region + '/' + $service + '/' + 'aws4_request'
$canonical_querystring = 'X-Amz-Algorithm=AWS4-HMAC-SHA256'
$canonical_querystring += '&X-Amz-Credential=' + [uri]::EscapeDataString(($access_key + '/' + $credential_scope))
$canonical_querystring += '&X-Amz-Date=' + $amz_date
$canonical_querystring += '&X-Amz-Expires=300'
$canonical_querystring += '&X-Amz-SignedHeaders=' + $signed_headers
$canonical_headers = 'host:' + $host1 + "`n"
$canonical_request = $method + "`n"
$canonical_request += "/" + $key + "`n"
$canonical_request += $canonical_querystring + "`n"
$canonical_request += $canonical_headers + "`n"
$canonical_request += $signed_headers + "`n"
$canonical_request += "UNSIGNED-PAYLOAD"
$algorithm = 'AWS4-HMAC-SHA256'
$canonical_request_hash = hash -request $canonical_request
$string_to_sign = $algorithm + "`n"
$string_to_sign += $amz_date + "`n"
$string_to_sign += $credential_scope + "`n"
$string_to_sign += $canonical_request_hash
$signing_key = getSignatureKey $secret_key $datestamp $region $service
$signature = HmacSHA256 -secret $signing_key -message $string_to_sign
$signature = ($signature|ForEach-Object ToString x2) -join ''
$canonical_querystring += '&X-Amz-Signature=' + $signature
$request_url = "http://" + $host1 + "/" + $key + "?" + $canonical_querystring
# Write-Host $request_url
# Using Curl:
# curl.exe '-s', '--retry', '3', '--retry-delay', '10', '-X', 'PUT', '-T', $local_file, $request_url
# Or just put to the URL directly:
Invoke-RestMethod -Uri $request_url -Method Put -InFile $local_file
Related
The term 'googet' is not recognized as the name of a cmdlet, function, script file, or operable program
I am following the instructions in here to install the Ops agent on my local Windows machine. These are the steps that I follow in PowerShell (as admin): (New-Object Net.WebClient).DownloadFile("https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.ps1", "${env:UserProfile}\add-google-cloud-ops-agent-repo.ps1") Invoke-Expression "${env:UserProfile}\add-google-cloud-ops-agent-repo.ps1 -AlsoInstall" As soon as I execute this, the output is: googet : The term 'googet' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Users\bot_runner_01\add-google-cloud-ops-agent-repo.ps1:171 char:10 + if (! (googet listrepos | Select-String -quiet "https://packages.cl ... + ~~~~~~ + CategoryInfo : ObjectNotFound: (googet:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException googet : The term 'googet' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Users\bot_runner_01\add-google-cloud-ops-agent-repo.ps1:198 char:24 + if (! $Version -and (googet listrepos | Select-String -quiet "https ... + ~~~~~~ + CategoryInfo : ObjectNotFound: (googet:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException googet : The term 'googet' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Users\bot_runner_01\add-google-cloud-ops-agent-repo.ps1:205 char:10 + if (! (googet installed google-cloud-ops-agent 2>&1 | Select-String ... + ~~~~~~ + CategoryInfo : ObjectNotFound: (googet:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException No changes made. How can I fix this? thank you
I had the same issue, found that running the 'Installing the guest environment' scripts in the page below worked for me: https://cloud.google.com/compute/docs/images/install-guest-environment?authuser=0#installing_guest_environment
Join-Path : Cannot bind argument to parameter 'Path' because it is null
I want to build this open source project from source for contributing. I am following this docs for windows. I cloned the repo and install chocolatey as mention. Then I am executing the commands in "prepare the enviorment section" . I was able to run 1st command correctly PS A:\wasmedgebuild\WasmEdge> choco install cmake ninja vswhere But when I run second one . PS A:\wasmedgebuild\WasmEdge> $vsPath = (vswhere -latest -property installationPath) Import-Module (Join-Path $vsPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll") Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments "-arch=x64 -host_arch=x64 -winsdk=10.0.19041.0" I am getting this error: Join-Path : Cannot bind argument to parameter 'Path' because it is null. At line:2 char:26 + Import-Module (Join-Path $vsPath "Common7\Tools\Microsoft.VisualStudi ... + ~~~~~~~ + CategoryInfo : InvalidData: (:) [Join-Path], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand Enter-VsDevShell : The term 'Enter-VsDevShell' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:3 char:1 + Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCm ... + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Enter-VsDevShell:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Screenshot I don't know what is the problem. Am I doing it in wrong way?
Executing c++ code in VS code without script failed
While Executing the c++ code on VS through command terminal, getting below error. Coupld you please comment on this. PS D:\Test> .\a.exe Program 'a.exe' failed to run: The system cannot find the file specifiedAt line:1 char:1 + .\a.exe + ~~~~~~~. At line:1 char:1 + .\a.exe + ~~~~~~~ + CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException + FullyQualifiedErrorId : NativeCommandFailed PS D:\Test>
Elastic Beanstalk post install script won't execute correctly
I want to publish a .NET core application to Elastic Beanstalk and they will be running on Windows Server. I want to make some changes to IIS settings... more precisely Queue Length of Application Pool. I have aws-windows-deployment-manifest.json file with the following content { "manifestVersion": 1, "deployments": { "aspNetCoreWeb": [ { "name": "my-dotnet-core-app", "scripts": { "postInstall": { "file": "SetupScripts/setupAppPool.ps1" } } } ] } } Inside setupAppPool.ps1 script is the following content: Import-Module WebAdministration $defaultAppPool = Get-ItemProperty IIS:\AppPools\DefaultAppPool #$defaultAppPool.PSPath Write-Host "Display Queue Length before change: " -NoNewline (Get-ItemProperty IIS:\AppPools\DefaultAppPool\).queueLength #Value changed here Set-ItemProperty -Path $defaultAppPool.PSPath -Name queueLength -Value 3000 Write-Host "Display Queue Length after change: " -NoNewline (Get-ItemProperty IIS:\AppPools\DefaultAppPool\).queueLength If it will be a simple scritp like hostname it executes with no problem, however this one fails with the following error: 2022-07-12 17:41:25,025 [INFO] Running config InfoTask-TailLogs AWS.DeploymentCommands.2022.07.12-17.40.30.log: Starting deployment for my-dotnet-core-app of type AspNetCoreWeb Parameters: appBundle: . iisPath: / iisWebSite: Default Web Site Starting restart of my-dotnet-core-app ---------- Executing command "C:\Windows\system32\iisreset.exe /restart" ---------- ---------- CWD "" ---------- Attempting stop... Internet services successfully stopped Attempting start... Internet services successfully restarted ---------- Command complete with exit code 0 ---------- Starting ASP.NET Core web deployment my-dotnet-core-app at C:\inetpub\AspNetCoreWebApps\my-dotnet-core-app with IIS path Default Web Site/ Copying C:\staging\. to C:\inetpub\AspNetCoreWebApps\my-dotnet-core-app Removing existing application from IIS Adding application to IIS Commit changes to IIS ---------- Executing command "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy unrestricted -NonInteractive -NoProfile -Command "& { & \"C:\staging\SetupScripts/setupAppPool.ps1\"; exit $LastExitCode }" " ---------- ---------- CWD "C:\inetpub\AspNetCoreWebApps\my-dotnet-core-app" ---------- Get-ItemProperty : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). At C:\staging\SetupScripts\setupAppPool.ps1:2 char:19 + $defaultAppPool = Get-ItemProperty IIS:\AppPools\DefaultAppPool + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ItemProperty], ParameterBindingException + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemPropertyCommand Get-ItemProperty : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). At C:\staging\SetupScripts\setupAppPool.ps1:7 char:2 + (Get-ItemProperty IIS:\AppPools\DefaultAppPool\).queueLength + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ItemProperty], ParameterBindingException + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemPropertyCommand Set-ItemProperty : Cannot bind argument to parameter 'Path' because it is null. At C:\staging\SetupScripts\setupAppPool.ps1:10 char:24 + Set-ItemProperty -Path $defaultAppPool.PSPath -Name queueLength -Valu ... + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Set-ItemProperty], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetItemProp ertyCommand Get-ItemProperty : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). At C:\staging\SetupScripts\setupAppPool.ps1:13 char:2 + (Get-ItemProperty IIS:\AppPools\DefaultAppPool\).queueLength + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ItemProperty], ParameterBindingException + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemPropertyCommand Display Queue Length before change: Display Queue Length after change: ---------- Command complete with exit code 0 ---------- Error messages running the command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy unrestricted -NonInteractive -NoProfile -Command "& { & \"C:\staging\SetupScripts/setupAppPool.ps1\"; exit $LastExitCode }" Get-ItemProperty : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). At C:\staging\SetupScripts\setupAppPool.ps1:2 char:19 + $defaultAppPool = Get-ItemProperty IIS:\AppPools\DefaultAppPool + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ItemProperty], ParameterBindingException + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemPropertyCommand Get-ItemProperty : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). At C:\staging\SetupScripts\setupAppPool.ps1:7 char:2 + (Get-ItemProperty IIS:\AppPools\DefaultAppPool\).queueLength + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ItemProperty], ParameterBindingException + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemPropertyCommand Set-ItemProperty : Cannot bind argument to parameter 'Path' because it is null. At C:\staging\SetupScripts\setupAppPool.ps1:10 char:24 + Set-ItemProperty -Path $defaultAppPool.PSPath -Name queueLength -Valu ... + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Set-ItemProperty], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetItemProp ertyCommand Get-ItemProperty : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). At C:\staging\SetupScripts\setupAppPool.ps1:13 char:2 + (Get-ItemProperty IIS:\AppPools\DefaultAppPool\).queueLength + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ItemProperty], ParameterBindingException + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemPropertyCommand ---------- Executing command "C:\Windows\system32\iisreset.exe /start" ---------- ---------- CWD "" ---------- Attempting start... Internet services successfully started ---------- Command complete with exit code 0 ---------- AWSCommandWrapper.log: How can I solve this problem?
cloudformation windows userdata cfn-init.exe end of line issues
Working through adding some cfn-init to request data from an S3 bucket. I believe I've got a syntax problem with the cfn-init.exe call from powershell but cannot seem to find where. This structure was taken from the Bootstrapping AWS CloudFormation Windows Stacks AWS Example. I've also tried adapting from the bash structure from AWS cfn-init documentation with no success. "UserData": {"Fn::Base64": {"Fn::Join": ["\n", [ "<powershell>", ... "cfn-init.exe -v -s", { "Ref" : "AWS::StackName" }, " -r EC2Instance", "</powershell>" "Metadata" : { "AWS::CloudFormation::Init" : { "config": { "files" : { "C:\\chef\\validator.pem" : { "source" : "https://s3.amazonaws.com/dtcfstorage/validator.pem", "authentication" : "s3creds" } } }, "AWS::CloudFormation::Authentication" : { "s3creds" : { "type" : "S3", "roleName" : "awss3chefkeyaccess" } } } } The cfn-init.exe is being run but errors out as the arguments are passing to new lines: 2018/05/21 15:35:08Z: Message: The errors from user scripts: Usage: cfn-init.exe [options] or: cfn-init.exe [options] or: cat | cfn-init.exe [options] - cfn-init.exe: error: -s option requires an argument cloudinittest : The term 'cloudinittest' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Windows\TEMP\UserScript.ps1:30 char:1 + cloudinittest + ~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (cloudinittest:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException -r : The term '-r' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Windows\TEMP\UserScript.ps1:31 char:2 + -r EC2Instance + ~~ + CategoryInfo : ObjectNotFound: (-r:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
It's because you have joined using \n at the top. Every arg to the join function will separate by a newline event if you type some on the same line! Therefore, your command cfn-init has been interpreted as: cfn-init.exe -v -s stack-name -r EC2Instance ... Since the line is broken, the command doesn't get run properly. As such, you can join by a space character. You can try replacing the above by this: {"Fn::Join": [" ", ["cfn-init.exe -v -s", {"Ref":"AWS::StackName"}, "-r EC2Instance"]}