【问题标题】:Powershell unable to get group SID while using remoting via azure pipeline通过 azure 管道使用远程处理时,Powershell 无法获取组 SID
【发布时间】:2021-09-22 16:25:48
【问题描述】:

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

无法连接服务器。这可能是因为这台服务器不存在,它目前处于关闭状态, 或者它没有运行 Active Directory Web 服务。

我怀疑正在运行我的脚本的当前服务器在使用 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
    }

【问题讨论】:

    标签: windows azure powershell windows-server-2016


    【解决方案1】:

    想通了

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-10
      • 2019-06-14
      • 2021-04-22
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      相关资源
      最近更新 更多