无法在远程 PS 会话 (Powershell) 中查询 [Get-QADComputer] 信息

发布于 2024-11-25 09:15:10 字数 966 浏览 3 评论 0原文

当我运行下面的脚本以使用 quest ad commandlet 提取 OU 信息时,它会给出如下错误 下面

Object reference not set to an instance of an object.
+ CategoryInfo          : NotSpecified: (:) [Get-QADComputer], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.GetComputerCmdlet

是正在使用的脚本

$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

有人可以帮我解决这个问题吗?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你丑哭了我 2024-12-02 09:15:10

您不需要从远程会话中运行 QAD,您可以从管理站尝试:

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

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
滥情哥ㄟ 2024-12-02 09:15:10

我认为问题在于您声明然后调用该脚本块的方式。未经测试,但我认为这可能会更好:

 Invoke-Command -Session $session -ScriptBlock {
 Add-PSSnapin Quest.ActiveRoles.ADManagement
       }
 $ou = {get-qadcomputer QUAG | select -ExpandProperty canonicalname}

 $adou= (Invoke-Command -Session $session  -ScriptBlock $ou)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文