When I ran the following cmdlets, I got the above error:
Get-Process -computerName (import-csv D:computers.csv | select -expand hostname)
Inside the computers.csv file, I have:
hostname,operatingsystem
localhost,windows7
ck-acer,windows7
xu_xps,windows8
, where localhost and ck-acer are the same for the local PC, xu_xps is a laptop in the home group.
I narrowed the problem down to producing the same error message even with the following cmdlet:
Get-Process -computerName localhost
Solution (sometimes):
Start the Remote Registry service
Problem 2:
On a different instance, I got the above error again even though the Remote Registry service has started on both machines.
I have two PCs in a homegroup. CK-Acer is a Win 7 laptop, xu_xps is a Win 8.1 laptop, Both PCs have Powershell v4 installed. I have created the same account and password on the two machines. When I run whoami, the machines show: ck-acer\charlie and xu_xps\charlie, respectively.
However, when I run the following cmdlets on ck-acer with the admin privilege, they all failed:
gps -c xu_xps #### gps : Couldn't connect to remote machine.
get-service -ComputerName xu_xps ### get-service : Cannot open Service Control Manager on computer 'xu_xps'. This operation might require other privileges.
Enter-PSSession -ComputerName xu_xps ### Enter-PSSession : Connecting to remote server xu_xps failed with the following error message : Access is denied. (I already run enable-psremoting and set-item WSMan:\localhost\Client\TrustedHosts *)
Reason:
When I run the cmdlet on the local PC (ck-acer), the execution is account 'Charlie' with the admin privilege. However, that account does not pass through to the remote machine. As the local machine is in a homegroup, the account is changed to CK-Acer\HomeGroupUser$ on the XU_XPS remote machine. In the same token, the account 'Charlie' from the remote PC (XU_XPS) becomes XU_XPS\HomeGroupUser$ on the local PC (CK-Acer) . You can check if the account has been transformed on Control Panel|User Accounts and Family Safety|User Accounts|Manage Your Credentials|Windows Credentials
Solution:
On the local machine CK-Acer, update the account with the same user name and password to match the account 'Charlie', but with Xu_XPS as the network name.
To make the change persistent after logging off or restarting machine, you need to change the default selection from “Allow Windows to Manage HomeGroup Connections” to “Use User Accounts and Passwords to Connect to Other Computers”.
This settings could be found on the bottom of Advanced Sharing Settings (Control panel / Network and Internet / Network and Sharing Center / Advanced Sharing Settings)