0
votes

Not exactly sure why I am getting this error - input object cannot be bound to any parameters for the command either because the commmand does not take pipeline input and its properties do not match any of the parameters that take pipeline input. Any assistance is appreciated

Code snippet below

$Session = New-PSSession -ComputerName DC1 -Credential $Cred
Import-Module ActiveDirectory -PSSession $Session
$comp = $env:COMPUTERNAME
if ($ComputerName -eq $null) {
Invoke-Command -Session $session  -ScriptBlock {$using:PC 
}
if($comp.substring(5,3) -imatch "Dbs"){
Get-ADObject $PC |
Move-ADObject  -Targetpath "ou=Database, 
dc=com,dc=company,dc=net"
Write-Host "Moved to Datbases"}

 }


Remove-PSSession -Session $Session
2
You don't need to establish a remote session to move a computer object if you have the permissions in AD. - Bill_Stewart
establishing a remote session is a requirement - Henry B
"establishing a remote session is a requirement" - not correct, unless you are saying it's a business requirement. It's not a technical requirement. - Bill_Stewart

2 Answers

0
votes

Have you tried getting the object explicitly?

$Session = New-PSSession -ComputerName DC01 -Credential $Cred
Import-Module ActiveDirectory -PSSession $Session
$comp = $env:COMPUTERNAME
if($comp.substring(5,3) -imatch "Sys")
{
    $adObject = Get-ADObject -Filter {Name -eq $comp} 
    Move-ADObject -Identity $adObject -Targetpath "ou=System Servers,ou=PRD,ou=Servers,dc=com,dc=myCompany,dc=net" 
}
    elseif($comp.substring(5,3) -imatch "App")
{
0
votes

You are both piping in the output of Get-ADComputer and also defining the -Identity property which are conflicting. Chose one way or the other.

Get-ADComputer $comp | Move-ADObject -Targetpath "ou=Database, dc=com,dc=company,dc=net"

or

$ADComputer = Get-ADComputer $comp
Move-ADObject -Identity $ADComputer -Targetpath "ou=Database, dc=com,dc=company,dc=net"