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

只愿长相守 提交于 2019-12-25 01:58:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!