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 Answers
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.

answered 2 years ago
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
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions