Search code examples
arrayspowershellpowershell-remoting

Unable to query [Get-QADComputer] info in Remote PS Sessions (Powershell)


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!


Solution

  • 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