【问题标题】:Issue Connecting to remote server问题连接到远程服务器
【发布时间】:2017-09-02 08:23:19
【问题描述】:

所以我使用 powershell 脚本构建 Json 文件,以确保所有域站点的所有软件版本都是最新的(使用不同域名的几个不同数据中心。我有一个特殊的 vpn信任所有域,因此我可以通过我的笔记本电脑毫无问题地访问所有域。

我起初认为这是一个凭据问题,所以我删除了该部分,但它似乎是网络级别的,我不确定为什么我可以 RDP、浏览到网络路径等。

连接到远程服务器 servera 失败,出现以下错误 消息:WinRM 无法处理该请求。以下错误 使用 Kerberos 身份验证时发生:找不到计算机 服务器验证计算机是否存在于网络中,并且 提供的名称拼写正确。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。 + CategoryInfo : OpenError: (servera:String) [], PSRemotingTransportException + FullyQualifiedErrorId : NetworkPathNotFound,PSSessionStateBroken

[CmdletBinding()]
Param (
    [Parameter(ValueFromPipeline = $true,
        ValueFromPipelinebyPropertyName = $true)]
    [Alias("Servers")]
    [string[]]$Name = (Get-Content "c:\versioncheck\servers.txt"),  
    [string]$Credential = "svcStatusCheck",
    [string]$PathToCred = "c:\versioncheck"
)
Begin {
    Function Get-Credentials {
        Param (
            [String]$AuthUser = $env:USERNAME
        )
        $Key = [byte]29, 36, 18, 74, 72, 75, 85, 52, 73, 44, 0, 21, 98, 76, 99, 28


        $CredFile = $AuthUser.Replace("\", "~")
        $File = $PathToCred + "\Credentials-$CredFile.crd"

        If (-not (Test-Path $File)) {
            (Get-Credential $AuthUser).Password | ConvertFrom-SecureString -Key $Key | Set-Content $File
        }

        $Password = Get-Content $File | ConvertTo-SecureString -Key $Key
        $AuthUser = (Split-Path $File -Leaf).Substring(12).Replace("~", "\")
        $AuthUser = $AuthUser.Substring(0, $AuthUser.Length - 4)
        $Credential = New-Object System.Management.Automation.PsCredential($AuthUser, $Password)
        Return $Credential
    }
}
Process {

    $AllServers = @()

    ForEach ($Computer in $Name) {
        $AllServers += $Computer
    }
}

End {
    ForEach ($Computer in $AllServers) {
        Write-Host "$(Get-Date): Script begins!"

        write-host "Checking $computer"
        Invoke-Command -cn $computer -credential $Credential -ScriptBlock { Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object @{Label = "ServerName"; Expression = {$env:computername}}, DisplayName, Publisher, DisplayVersion,InstallDate | Where-object { $_.Publisher -match "Software" } | ConvertTo-Json -depth 100 | Out-File "c:\versioncheck\InstalledApps.json"}
    } 
}

【问题讨论】:

  • 也许这是相关的:stackoverflow.com/a/30747948/45375
  • 一些旁白:[byte]29, 36, 18, 74, 72, 75, 85, 52, 73, 44, 0, 21, 98, 76, 99, 28 不会创建 [byte[]] 数组 - 使用 [byte[]] (29, 36, ...)。您的 process 块无法按预期使用管道输入 - 将 $AllServers = @() 放入您的 begin 块中,并在您的 $AllServers += $Name 块中使用 process
  • 另外:最好avoid Write-Host

标签: powershell


【解决方案1】:

您需要在使用enable-psremoting cmdlet 接收命令的远程计算机上启用 psremoting。此 cmdlet 准备一台机器以接收从 WS-MAN 发送的 Windows Powershell 命令

Enable-PSRemoting

【讨论】:

  • 都启用了 psremoting。我从他们身上运行其他脚本来检查磁盘空间、cpu、内存等。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-19
  • 1970-01-01
  • 2023-03-04
  • 2018-12-18
  • 2017-09-16
相关资源
最近更新 更多