【问题标题】:Unable to run PowerShell script across domains无法跨域运行 PowerShell 脚本
【发布时间】:2019-05-20 15:19:29
【问题描述】:

我正在尝试编写一个脚本来跨域检索任何过期的 IIS 证书。我可以在与服务器列表相同的域上运行脚本而不会出现任何错误,但即使我使用的用户具有所有域的管理员访问权限,我也无法跨域。

我尝试使用 New-PSSesiion 并将其传递到 Invoke-Command 中,但出现错误:WindRM 无法处理请求。

cd C:\Deploy\Certs

Enable-PSRemoting –force

            #set up path and user variables
            $AESKeyFilePath = “aeskey.txt” # location of the AESKey                
            $SecurePwdFilePath = “credpassword.txt” # location of the file that hosts the encrypted password                
            $user = "DOMAIN\Username" # User account login 

            #use key and password to create local secure password
            $AESKey = Get-Content -Path $AESKeyFilePath 
            $pwdTxt = Get-Content -Path $SecurePwdFilePath
            $securePass = $pwdTxt | ConvertTo-SecureString -Key $AESKey

           #crete a new psCredential object with required username and password
            $adminCreds = New-Object System.Management.Automation.PSCredential($user, $securePass)



$ServerList=Get-Content .\components\hosts.txt

foreach ( $Server in $ServerList ) {
    Write-Host "Checking $Server is up"
     if ( ( Test-Connection $Server -Quiet ) -eq $True ) {

     # Open remote session:
 #$session = New-PSSession -ComputerName $Server -Credential  $adminCreds -ThrottleLimit 16


Invoke-Command -ComputerName $Server -ScriptBlock  {

Import-Module -Name WebAdministration

Get-ChildItem -Path IIS:SSLBindings | ForEach-Object -Process `
 {
    if ($_.Sites)
    {
        $certificate = Get-ChildItem -Path CERT:LocalMachine/My |
        Where-Object -Property Thumbprint -EQ -Value $_.Thumbprint



        [PsCustomObject]@{
            HostName                     = $Env:COMPUTERNAME
            Sites                        = $_.Sites.Value
            CertificateFriendlyName      = $certificate.FriendlyName
            CertificateDnsNameList       = $certificate.DnsNameList
            CertificateExpiration         = $certificate.NotAfter
            CertificateIssuer            = $certificate.Issuer
        }  


    } 

}  
   }|  Out-File .\expired_Certs.txt -append #-NoTypeInformation
  } 
  }  

错误信息:

WinRM 无法处理该请求。带有错误代码的以下错误 0x80090311 使用 Kerberos 身份验证时发生:我们无法签名 您使用此凭据,因为您的域不可用。制作 确保您的设备已连接到您组织的网络并尝试 再次。如果您之前在此设备上使用其他设备登录过 凭据,您可以使用该凭据登录。

【问题讨论】:

标签: powershell cross-domain remote-access invoke-command


【解决方案1】:

已解决!我阅读了故障排除帮助并运行以下命令将服务器添加到受信任的主机:

Set-Item wsman:localhost\client\trustedhosts *.domain.name

【讨论】:

    猜你喜欢
    • 2020-12-05
    • 2021-05-13
    • 2016-07-13
    • 2013-01-02
    • 2018-03-21
    • 2016-09-14
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    相关资源
    最近更新 更多