我创建了以下过程以获取远程计算机上已安装程序的列表。我在我的计算机上测试它并且工作正常,但是当我尝试在我的网络中使用时,我收到以下错误。
我正在以网络管理员身份运行它。
代码:
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
答案 0 :(得分:0)
正如许多其他人指出的那样,您的问题是您无法通过WinRM创建PSSession。 PSRmoting over WinRM是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
}
作为旁注,请记住,在x64系统上,您需要在WOW6432Node
中检查32位应用。