问题
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!
回答1:
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
回答2:
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)
来源:https://stackoverflow.com/questions/6788966/unable-to-query-get-qadcomputer-info-in-remote-ps-sessions-powershell