--ref: http://searchsystemschannel.techtarget.com/feature/PowerShell-remoting-in-Windows-Server-2008-R2
--1. enable remote on server e.g. xxx
PS C:\Users\oraexec> Enable-PSRemoting
WinRM Quick Configuration
Running command "Set-WSManQuickConfig" to enable this machine for remote management through WinRM service.
This includes:
1. Starting or restarting (if already started) the WinRM service
2. Setting the WinRM service type to auto start
3. Creating a listener to accept requests on any IP address
4. Enabling firewall exception for WS-Management traffic (for http only).
Do you want to continue?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y
WinRM already is set up to receive requests on this machine.
WinRM has been updated for remote management.
Created a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine.
WinRM firewall exception enabled.
Confirm
Are you sure you want to perform this action?
Performing operation "Registering session configuration" on Target "Session configuration "Microsoft.PowerShell32" is
not found. Running command "Register-PSSessionConfiguration Microsoft.PowerShell32 -processorarchitecture x86 -force"
to create "Microsoft.PowerShell32" session configuration. This will restart WinRM service.".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y
PS C:\Users\oraexec>
--2. add to trust on client
If you are managing a remote computer from a computer that is running Windows 7, start the Windows Remote Management (WinRM) service to allow for the addition of trusted hosts. Open a Command Prompt session with elevated user rights by clicking Start, clicking All Programs, clicking Accessories, right-clicking Command Prompt, and then clicking Run as administrator. Type the following, and then press Enter: net start winrm
For remote connections in a Workgroup to Workgroup/Domain scenario, the remote computer must be added to the trusted hosts list on the source computer. To do this, run the following command on the source computer in a Command Prompt window that is opened with elevated user rights.
winrm set winrm/config/client @{TrustedHosts="RemoteComputerName"}
For remote connections in a Workgroup to Workgroup/Domain scenario, if a user is not logged on by using the source computer’s built-in administrator account, the following WinRM registry key must be configured to allow remote access from the source computer. This change is required because of a User Account Control (UAC) limitation on non-administrator accounts that are members of the Administrators group. To change this registry key, run the following command on the source computer at a command prompt that is opened with elevated user rights.
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
By default, WinRM allows for a maximum of five connections to a remote computer to be active per user. To increase the limit, run the following command on the source computer, in which X represents the number of connections that you want to allow, at a command prompt that is opened with elevated user rights.
winrm s winrm/config/winrs @{MaxShellsPerUser="X"}
winrm set winrm/config/client @{TrustedHosts="xxxxx"}
--3. run powershell on client
$host.version
--4. test connection with remote
PS H:\> Test-WSMan xxxxx
wsmid : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor : Microsoft Corporation
ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 2.0
--remote commands
Invoke-Command -ComputerName Monolith -ScriptBlock { Get-ChildItem C:\ } -credential chris
Invoke-Command [-FilePath]
Invoke-Command -ScriptBlock {E:\scripts\test.cmd} -ComputerName cepaoas91 -credential cepaoas91\oraremote
--5. enter remote session
Enter-PSSession -ComputerName server1 -Credential domain\user
Enter-PSSession -ComputerName server1 -Credential domain\user