我正在尝试从服务器在 DC 上运行以下脚本,但我不断收到错误消息
Cannot bind parameter 'Identity'. Cannot convert value "1" to type "Microsoft.ActiveDirectory.Management.ADComputer". Error:
"Invalid cast from 'System.Char' to 'Microsoft.ActiveDirectory.Management.ADComputer'."
+ CategoryInfo : InvalidArgument: (:) [Get-ADComputer], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
+ PSComputerName : dc-test.com
脚本代码:
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $password
$list = gc c:\test.txt
#example of what i would contain $i= Workstation1-"ou=test,dc=test,dc=com"
foreach ($i in $list)
{
$s=$i.Split('-')
$ScriptBlock = {
param ($s)
Import-Module ActiveDirectory
get-adcomputer $s[0] | Move-ADObject -TargetPath $s[1]
}
invoke-command -computer dc.test.com -Argu $s -scriptblock $ScriptBlock -cred $Credentials
}
}
当我在 DC 上运行它时,它工作正常。有人可以指出我正确的方向吗?