【发布时间】:2021-03-05 22:42:47
【问题描述】:
我在尝试将安全字符串传递给 powershell 脚本时遇到问题,但又出现此错误?
无法处理参数“密码”的参数转换。 无法将“System.String”类型的“ConvertTo-SecureString”值转换为“System.Security.SecureString”类型。
$SecureServiceAccountPassword = ConvertTo-SecureString "somethingstong!" -AsPlainText -Force
$AgentAccount = "myAccount"
$ServiceAccountOU = "MYOU"
POWERSHELL -COMMAND $ADAccountScript -ServiceAccountOU $ServiceAccountOU -Account $AgentAccount -Password $SecureAgentAccountPassword
它调用的脚本是这个。
param(
##MasterKey for KeePass currently stored in a DB.
[Parameter(Position=0,mandatory=$true)]
[string] $ServiceAccountOU,
##Account to be created in AD
[Parameter(Position=1,mandatory=$true)]
[string] $Account,
[Parameter(Position=2,mandatory=$true)]
[SecureString] $Password
)
NEW-ADUSER -Name $Account -AccountPassword $Password -Path $SrviceAccountOU -Enabled $True -PasswordNeverExpires $True -CannotChangePassword $True
【问题讨论】:
-
错误表明您正在传递字符串,而不是安全字符串,请执行此操作
NEW-ADUSER -Name $Account -AccountPassword (ConvertTo-SecureString -AsPlainText -Force)$Password -
但这就是传入的内容?
-
$SecureServiceAccountPassword = ConvertTo-SecureString "somethingstong!" -AsPlainText -Force
标签: powershell