繁体   English   中英

SSM - AWS-RunPowerShellScript - $false 布尔值被错误地识别为字符串

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM