0

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!

PowerShell
  • 1,991
  • 8
  • 35
  • 57

2 Answers2

2

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
Shay Levy
  • 121,444
  • 32
  • 184
  • 206
  • Hi @Shay Levy Can you please help me out with this question http://stackoverflow.com/questions/7021326/combining-output-of-two-cmdlets-to-get-a-common-output – PowerShell Aug 11 '11 at 07:48
  • Hi @Shay Levy i have appended the question with output of two cmdlets which would be used, could you please check it out http://stackoverflow.com/questions/7021326/combining-output-of-two-cmdlets-to-get-a-common-output – PowerShell Aug 11 '11 at 09:22
  • Hi @Shay Levy can you please help me with this question http://stackoverflow.com/questions/7104316/unable-to-extract-virtualnetwork-name-using-scvmm-powershell-modules – PowerShell Aug 18 '11 at 09:02
0

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)
mjolinor
  • 66,130
  • 7
  • 114
  • 135