Why I cant use Get-QADComputer inside a job?

why the Quest.ActiveRoles.ADManagement is not available inside a job ?

Ok when running interractively :

PS>Get-QADComputer -SearchRoot '$ou' -SizeLimit 200 |
    %{ if (Test-Connection -Quiet $_.name) { 
         $lastboottime = (Get-WmiObject -Class Win32_OperatingSystem -computername $_.name).LastBootUpTime;  
         $sysuptime = (Get-Date) - System.Management.ManagementDateTimeconverter]::ToDateTime($lastboottime)
write-host "$($_.name) allumé depuis $($sysuptime.days) jours" }  }

domain\comp1$ allumé depuis 8 jours
domain\comp2$ allumé depuis 0 jours

But when using job :

PS>start-job -Name uptime -ScriptBlock{Get-QADComputer -SearchRoot '$ou' -SizeLimit 200 |
        %{ if (Test-Connection -Quiet $_.name) { 
             $lastboottime = (Get-WmiObject -Class Win32_OperatingSystem -computername $_.name).LastBootUpTime;  
             $sysuptime = (Get-Date) - System.Management.ManagementDateTimeconverter]::ToDateTime($lastboottime)
    write-host "$($_.name) allumé depuis $($sysuptime.days) jours" }  }}

it complains to not find the command

PS>Receive-Job uptime -Keep
Le terme «Get-QADComputer» n'est pas reconnu comme nom d'applet de commande,
fonction, fichier de script ou programme exécutable. Vérifiez l'orthographe du
nom, ou si un chemin d'accès existe, vérifiez que le chemin d'accès est correct et
réessayez.
    + CategoryInfo          : ObjectNotFound: (Get-QADComputer:String) [], Command
   NotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    + PSComputerName        : localhost

Answers


Powershell jobs run in a seperate process, so try importing the module first in your scriptblock. Ex:

Start-Job -InitializationScript { Import-Module ...module here... } -Name uptime -ScriptBlock { ...your code.... }

Need Your Help

Right to left setting in dynatree

jquery dynatree

how to change Right to left setting in

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.