Powershell Get-Process : Couldn't connect to remote machine.

Problem 1:

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)



SQL Server 2008 R2 Installation Error: '' is not a valid login or you do not have permission.

Problem:

I try to install SQL Server 2008 R2 Developer edition on my 64-bit Acer laptop with Windows 7 Professional and get the above error.

Reason:

The computer name and the user account name is the same and the user account is selected as the default admin in the setup process.

Solution:

Either change the computer name or use a different user account with admin privilege.

Internet Explorer cannot open a local htm or html file

Scenario and Problem:

I try to run the following cmdlets
PS C:\Windows\system32> get-alias | convertto-html > aliases.html

Of course, that would produce a local aliases.html file at C:\Windows\System32

I can see the file in Windows Explorer:



But surprisingly, I cannot open it in IE,either through the File|Open, dragging the file into address bar, or the following cmdlet:

PS C:\Windows\system32> invoke-item aliases.html

I got an error message in IE: This page can’t be displayed. 
In Chrome, I got: This webpage is not found. No webpage was found for the web address: file:///C:/Windows/System32/aliases.html

But if I save the file to my own folder, everything works fine. So it is a security issue.

Solution:
Save the file to your own working folder, not to the system folder.

get-netfirewallrule: The term 'get-netfirewallrule' is not recognized as the name of a cmdlet, function, script file, or...

Requirement:

 Display a list of all Windows Firewall rules. 

Problem:

When I ran Get-netfirewallrule on my Windows 7 PC, I got an error as above in the title.

Reason:

This cmdlet is pretty new. It is only applicable to Windows 8.1, Windows Powershell 4.0, and Windows Server 2012 R2.

How to make get-service successfully accessing to another computer in homegroup in PowerShell?

Question:
Is there a way to retrieve a list of the services that are installed on a remote computer?

Answer:
Sure, I think get-service will do it. So let's take a look at the details of the cmdlet first:
Parameter Set: Default
Get-Service [[-Name] <String[]> ] [-ComputerName <String[]> ] [-DependentServices] [-Exclude <String[]> ] [-Include <String[]> ] [-RequiredServices] [ <CommonParameters>]

-ComputerName<String[]>

Gets the services running on the specified computers. The default is the local computer. Type the NetBIOS name, an IP address, or a fully qualified domain name of a remote computer. To specify the local computer, type the computer name, a dot (.), or "localhost".
This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Get-Service even if your computer is not configured to run remote commands.
So I decide to create a homework with two computers to test this cmdlet. But I have encountered a couple of errors as below.

Problem 1 - Homegroup cannot be created due to an error: Microsoft Teredo Tunneling Adapter - Device cannot start code 10
Unfortunately, I encounter the following error when I try to establish the homegroup:

Microsoft Teredo Tunneling Adapter - Device cannot start code 10

Reason: 
Further investigation indicates that the problem is associated with the IPV6 disabled. A while ago, when I tested IP and DNS with Powershell, I found the address was for IPV6, not the conventional IPV4 address. So I decide to "Prefer IPv4 over IPv6 in prefix policies" (https://support.microsoft.com/kb/929852?wa=wsignin1.0), which causes the problem.

Solution for Problem 1:

To fix it, enable IPV6 by setting the DisabledComponents value to 0 at: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TCPIP6\Parameters\

After IPV6 is fixed, the Microsoft Teredo Tunneling Adapter works fine, and a homegroup was successfully created between two local laptops: xu-acer (localhost) and xu_xps (acting as the remote pc).

Problem 2 Get-Service : Cannot open Service Control Manager on computer 'xu_xps'. This operation might require other privileges.



Solution for Problem 2 (based on the suggestion on http://stackoverflow.com/questions/10744903/cant-use-get-service-computername-on-remote-computer):

(a). Make the two PCs in the same homework

(b). Create the same user account with an administrator privilege on the two machines (the same user name and password. The prefix is different, of course. In my case, on the local host, the user is xu-acer\Charlie, the user on the remate PC is xu_xps\Charlie).

(c) Run powershell with the same user account on the two PCs

(d) On the remote PC, run the following :

Enable-PSRemoting
Set-Item WSMan:\localhost\Client\TrustedHosts * #### to enable the server (localhost) to enter the current client (remote) machine.######

(e) Then re-run the cmdlet, it should work.