无法在远程PS会话(Powershell)中查询[Get-QADComputer]信息



当我运行下面的脚本使用quest and commandlets提取OU信息时,它给了我一个错误,如下

Object reference not set to an instance of an object.
+ CategoryInfo          : NotSpecified: (:) [Get-QADComputer], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.GetComputerCmdlet

下面是使用

的脚本
$password = convertTo-secureString -string "123" -asPlainText -force 
$credential = new-object System.Management.automation.Pscredential ("test.comsh" , $password) 
$session = New-PSSession -computername CI -credential $credential -port 5985 -Authentication Default
Invoke-Command -Session $session -ScriptBlock {
Add-PSSnapin Quest.ActiveRoles.ADManagement
$ou = get-qadcomputer QUAG | select -ExpandProperty canonicalname
}
$adou= (Invoke-Command -Session $session  -ScriptBlock { $ou })
Get-PSSession | Remove-PSSession
$adou
有谁能帮我一下吗?

谢谢!

您不需要在远程会话中运行QAD,您可以从管理站尝试:

Add-PSSnapin Quest.ActiveRoles.ADManagement
$pw = read-host "Enter password" -AsSecureString
Connect-QADService -Service 'server.company.com' -ConnectionAccount 'companyadministrator' -ConnectionPassword $pw
Get-QADComputer QUAG | Select-Object -ExpandProperty CanonicalName

我认为问题是你的方式声明,然后调用脚本块。没有测试,但我认为这可能会更好:

 Invoke-Command -Session $session -ScriptBlock {
 Add-PSSnapin Quest.ActiveRoles.ADManagement
       }
 $ou = {get-qadcomputer QUAG | select -ExpandProperty canonicalname}
 $adou= (Invoke-Command -Session $session  -ScriptBlock $ou)

最新更新