0
votes

I created the procedure below to get the list of the installed programs on a remote machine. I tested it on my computer and it worked fine, but when I try to use in my network I am getting the error below.

I am running it as network admin.

Code:

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:

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
1
Did you actually bother reading the error message? - Ansgar Wiechers
you need to establish a connection to your remote machine first. Get-Help WinRM - Will Webb
The error message is quite clear. You should look into WinRM as advised by @WillWebb and also look into Powershell Remoting. - Jeff Zeitlin
@ChrisCaviness - I don't see any haxxoring here; he's looking for the INSTALLED programs, not the RUNNING programs. This is legitimate information for an administrator to know. Whether he's a competent administrator or not is an entirely different question, and subject to evaluation based on his apparent inability to read and understand the error he's asking about - but I don't see anything to base an accusation of haxxoring on. - Jeff Zeitlin

1 Answers

0
votes

As many others pointed out, your issue is that you can't create a PSSession over WinRM. PSRemoting over WinRM is what's used by Invoke-Command. The easiest way to remedy this would be to run Enable-PSRemoting on the remote host. There are many guides to configuring this across your environment with things like Group Policy.

With that said, you could use a different method than WinRM to poll those registry values. For example, you could use [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey() (which I believe uses the Remote Registry service):

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

As a side note, remember that on x64 systems you'll need to check in WOW6432Node for the 32 bit apps.