I am trying to run the following script on a DC from a server and i keep getting the error
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
Script code:
$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
}
}
when I run it on the DC it works fine. Can someone point me in the right direction?