Unable to query [Get-QADComputer] info in Remote P

2019-09-08 21:46发布

When i run the below script to extract the OU info using quest ad commandlets it gives me an error as below

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

Below is The Script which is use

$password = convertTo-secureString -string "123" -asPlainText -force 
$credential = new-object System.Management.automation.Pscredential ("test.com\sh" , $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

Can Some one please help me with this?

Thanks!

2条回答
孤傲高冷的网名
2楼-- · 2019-09-08 22:06

You don't need to run QAD from within a remote session, you can try it from your admin station:

Add-PSSnapin Quest.ActiveRoles.ADManagement
$pw = read-host "Enter password" -AsSecureString
Connect-QADService -Service 'server.company.com' -ConnectionAccount 'company\administrator' -ConnectionPassword $pw
Get-QADComputer QUAG | Select-Object -ExpandProperty CanonicalName
查看更多
迷人小祖宗
3楼-- · 2019-09-08 22:23

I think the problem is with the way you're declaring and then invoking that script block. Not tested, but I think this might work better:

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

 $adou= (Invoke-Command -Session $session  -ScriptBlock $ou)
查看更多
登录 后发表回答