2017-04-18 129 views
0

我创建了以下程序以获取远程计算机上已安装程序的列表。我在我的电脑上测试过它,它运行良好,但是当我尝试在我的网络中使用时,出现下面的错误。获取远程计算机上已安装程序的列表

我正在运行它作为网络管理员。

代码:

Invoke-Command -ComputerName brpgd008 { 
    Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | 
    Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | 
    Format-Table –AutoSize > \\brspd010\c$\users\machael1\desktop\product1.txt 
} 

错误:

 
error:[brpgd008] Connecting to remote server failed with the following error 
message : WinRM cannot process the request. The following error occured while 
using Kerberos authentication : A specified logon session does not exist. It may 
already have been terminated. 
Possible causes are: 
    -The user name or password specified are invalid. 
    -Kerberos is used when no authentication method and no user name are specified. 
    -Kerberos accepts domain user names, but not local user names. 
    -The Service Principal Name (SPN) for the remote computer name and port does 
    not exist. 
    -The client and remote computers are in different domains and there is no trust 
    between the two domains. 
After checking for the above issues, try the following: 
    -Check the Event Viewer for events related to authentication. 
    -Change the authentication method; add the destination computer to the WinRM 
    TrustedHosts configuration setting or use HTTPS transport. 
Note that computers in the TrustedHosts list might not be authenticated. 
    -For more information about WinRM configuration, run the following command: 
    winrm help config. For more information, see the about_Remote_Troubleshooting 
    Help topic. 
    + CategoryInfo   : OpenError: (:) [], PSRemotingTransportException 
    + FullyQualifiedErrorId : PSSessionStateBroken 
+2

您是否真的烦读过错误信息? –

+2

您需要首先建立与远程机器的连接。 Get-Help WinRM –

+2

错误信息非常清晰。您应该像@WillWebb所建议的那样查看WinRM并查看Powershell Remoting。 –

回答

0

正如许多人指出的那样,你的问题是,你不能创造超过WinRM的PSSession的。通过WinRM进行PSRemoting是Invoke-Command使用的内容。最简单的方法是在远程主机上运行Enable-PSRemoting。有很多指导可以通过组策略等方式在您的环境中对其进行配置。

就是说,你可以使用与WinRM不同的方法来轮询这些注册表值。例如,你可以使用[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey()(我相信使用Remote Registry服务):

$ComputerName = "brpgd008" 
$RegLocation = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" 
$Values = "DisplayName", "DisplayVersion", "Publisher", "InstallDate" 
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $ComputerName) 

$RegKey= $Reg.OpenSubKey($RegLocation) 
$SubKeys = $RegKey.GetSubKeyNames() 

foreach ($SubKey in $SubKeys) { 
    $Output = New-Object -TypeName PSObject 
    $LeafKey = $Reg.OpenSubKey("$RegLocation$SubKey") 
    Foreach ($Value in $Values) { 
     Add-Member -InputObject $Output -MemberType NoteProperty -Name $value -Value ($LeafKey.GetValue($Value)) 
    } 
    $Output 
} 

作为一个侧面说明,请记住,在你需要在WOW6432Node检查的32位应用程序的x64系统。

相关问题