[英]SSM - AWS-RunPowerShellScript - $false boolean erroneously being recognized as String
我試圖在 SSM 中利用此文檔從 Active Directory 中刪除由 lambda 函數觸發的計算機對象。 我無法讓它根據需要識別 $false 布爾值以使 -Confirm 參數根據需要工作。 需要繞過使用該命令時出現的提示。
這是我試圖在命令部分中使用失敗來解決它的內容:
[boolean]::Parse('false')
$false = False, ([System.Convert]::ToBoolean($false))
$ConfirmPreference='None'
命令: Send-SSMCommand -DocumentName AWS-RunPowerShellScript -InstanceId i-0fb07c751beb53f97 -Parameter @{executionTimeout= '60'; commands=@("Remove-ADComputer -Credential $credentials -Identity $tag -Confirm:$false")}
Send-SSMCommand -DocumentName AWS-RunPowerShellScript -InstanceId i-0fb07c751beb53f97 -Parameter @{executionTimeout= '60'; commands=@("Remove-ADComputer -Credential $credentials -Identity $tag -Confirm:$false")}
使用 AWSPowershell.NetCore 4.0.1.1 和 SDK 3.1,盡管 3.X 版本也出現了同樣的問題(我去了最新版本,認為它可能有幫助)
Remove-ADComputer : Cannot convert 'System.String' to the type
'System.Management.Automation.SwitchParameter' required by parameter
'Confirm'.
At C:\ProgramData\Amazon\SSM\InstanceData\i-0fb07c751beb53f97\document\orchestr
ation\628c99dc-7a6a-4951-99ca-2d07127d678c\awsrunPowerShellScript\0.awsrunPower
ShellScript\_script.ps1:1 char:106
+ ... gement.Automation.PSCredential -Identity LAMBDA-7A9BB4 -Confirm:False
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-ADComputer], Parame
terBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.
Management.Commands.RemoveADComputer
在 SSM 控制台中查看命令時,在命令的“參數”窗格中,如果有幫助,命令如下所示:它從 lambda 函數中獲取變量的值
"Remove-ADComputer -Credential System.Management.Automation.PSCredential -Identity LAMBDA-7A9BB4 -Confirm:false" executionTimeout "60"
嘗試- -Confirm:0
Send-SSMCommand -DocumentName AWS-RunPowerShellScript -InstanceId i-0fb07c751beb53f97 `
-Parameter @{executionTimeout= '60'; commands=@("Remove-ADComputer -Credential `
$credentials -Identity $tag -Confirm:0")}
所有其他方法都是將字符串解析為-word- False
而不是它期望的實際布爾值0
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.