Move-ADObject - 无法找到命令的任何参数的输入对象 - 错误

时间:2017-11-17 14:50:06

标签: powershell

我不确定为什么会收到此错误 - 输入对象无法绑定到命令的任何参数,因为commmand不接受管道输入且其属性与任何接受管道输入的参数都不匹配。赞赏任何帮助

下面的代码段

$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 个答案:

答案 0 :(得分:0)

您是否尝试过显式获取对象?

$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")
{

答案 1 :(得分:0)

您既可以在Get-ADComputer的输出中输入,也可以定义相互冲突的-Identity属性。选择这种或那种方式。

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

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