AWS Send-SSMcommand parameter variable

1

I am trying to use a variable inside my command list like this

$Commands = @( '$DiskNumber = (Get-Partition -DriveLetter $driveletter).DiskNumber', 'Update-Disk -Number "$DiskNumber"', '$Size = Get-PartitionSupportedSize -DriveLetter $driveletter', 'Resize-Partition -DriveLetter $driveletter -Size $Size.SizeMax' ) $Parameter = @{ commands = $Commands }

however when I run the ssm command, its not recognizing the $driveletter variable which i defined earlier in the script.

if I put in letter instead of $driveletter, it works

any idea how to pass the variable inside the $commands list?

질문됨 2년 전545회 조회
2개 답변
0

you need to wrap variable with backticks. I also ran into this issue and to troubleshoot you just go to the location of the script on the host and look at the script, you'll notice with how you have it, if you look at the script (c:\programdata\amazon\ssm{instanceId}\document\orchestration{orchestrationID}\awsrunPowerShellScript\0.awsrunPowerShellscript_script.ps1) the variable doesnt even show up left of the equal sign.

so just wrap like `$DiskNumber` = (get-partition...).. Then open the script from path and look at it to troublshoot further.

답변함 2년 전
0

this is the error I am seeing. With or without back ticks

Get-Partition : Cannot validate argument on parameter 'DriveLetter'. The argument is null. Provide a valid value for 
the argument, and then try running the command again.
At C:\ProgramData\Amazon\SSM\InstanceData\i-0c02b9986c3c33057\document\orchestration\e4a27d78-e4ae-4fae-b45f-f528729b81
dc\awsrunPowerShellScript\0.awsrunPowerShellScript\_script.ps1:1 char:45
+ `$DiskNumber` = (Get-Partition -DriveLetter $driveletter).DiskNumber
+                                             ~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-Partition], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Get-Partition
 
$Size = : The term '$Size =' 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:\ProgramData\Amazon\SSM\InstanceData\i-0c02b9986c3c33057\document\orchestration\e4a27d78-e4ae-4fae-b45f-f528729b81
dc\awsrunPowerShellScript\0.awsrunPowerShellScript\_script.ps1:3 char:1
+ `$Size` = Get-PartitionSupportedSize -DriveLetter $driveletter
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ($Size =:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Resize-Partition : Cannot validate argument on parameter 'DriveLetter'. The argument is null. Provide a valid value 
for the argument, and then try running the command again.
At C:\ProgramData\Amazon\SSM\InstanceData\i-0c02b9986c3c33057\document\orchestration\e4a27d78-e4ae-4fae-b45f-f528729b81
dc\awsrunPowerShellScript\0.awsrunPowerShellScript\_script.ps1:4 char:31
+ Resize-Partition -DriveLetter $driveletter -Size $Size.SizeMax
+                               ~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Resize-Partition], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Resize-Partition
drago
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠