Powershell 在通过天蓝色管道使用远程处理时无法获取组 SID

Powershell unable to get group SID while using remoting via azure pipeline

我有一个脚本可以获取 2 个不同组的 SID,当我远程访问服务器并使用它的参数执行代码时,它可以完美地工作。我的问题是,当我将该脚本与 azure 管道一起使用时,代码失败并给我一个错误

unable to connect the server. This may be because this server does not exist, it is currently down, or it does not have the Active Directory Web Services running.

我怀疑 运行 我的脚本的当前服务器确实具有在使用 azure 管道时访问“main.ad.group.com”或“sub.ad.group.com”的正确凭据。我的脚本在“服务器 A”上 运行,但需要与“main.ad.group.com”或“sub.ad.group.com”通信以获取 SID。

代码

    $groupType = "Main"
    $group = "Group A"
    $SID = ""

    if ($groupType -eq "Main")
    {
        $SID = Get-ADGroup -server "main.ad.group.com" -Identity $group
        $SID = $SID.SID.value
    }
    elseif ($groupType -eq "Sub")
    {
        $SID = Get-ADGroup -server "sub.ad.group.com" -Identity $group
        $SID = $SID.SID.value
    }

想通了

 $user = "domain\user"
 $pass = "secret pass"
 $securePassword = ConvertTo-SecureString -String $pass -AsPlainText -Force

 $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $securePassword

 $groupType = "Main"
 $group = "Group A"
 $SID = ""

    if ($groupType -eq "Main")
    {

    $SID = Get-ADGroup -server "main.ad.group.com" -Identity $group -Credential $Credential
    $SID = $SID.SID.value
    }
    elseif ($groupType -eq "Sub")
    {
        $SID = Get-ADGroup -server "sub.ad.group.com" -Identity $group -Credential $Credential
        $SID = $SID.SID.value
    }