0

为什么 Quest.ActiveRoles.ADManagement 在工作中不可用?

交互运行时好的:

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

但是在使用作业时:

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" }  }}

它抱怨找不到命令

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
4

1 回答 1

1

Powershell 作业在单独的进程中运行,因此请先尝试在脚本块中导入模块。前任:

Start-Job -InitializationScript { Import-Module ...module here... } -Name uptime -ScriptBlock { ...your code.... }
于 2013-01-23T15:48:39.183 回答