TOPIC about_Remote_FAQ SHORT DESCRIPTION Contains questions and answers about running remote commands in Windows PowerShell. LONG DESCRIPTION When you work remotely, you type commands in Windows PowerShell on one computer (known as the "local computer"), but the commands run on another computer (known as the "remote computer"). The experience of working remotely should be as much like working directly at the remote computer as possible. Note: To use Windows PowerShell remoting, the remote computer must be configured for remoting. For more information, see about_Remote_Requirements. MUST BOTH COMPUTERS HAVE WINDOWS POWERSHELL INSTALLED? Yes. To work remotely, the local and remote computers must have Windows PowerShell, the Microsoft .NET Framework 2.0, and the Web Services for Management (WS-Management) protocol. Any files and other resources that are needed to execute a particular command must be on the remote computer. You must have permission to connect to the remote computer, permission to run Windows PowerShell, and permission to access data stores (such as files and folders), and the registry on the remote computer. For more information, see about_Remote_Requirements. HOW DOES REMOTING WORK? When you submit a remote command, the command is transmitted across the network to the Windows PowerShell engine on the remote computer, and it runs in the Windows PowerShell client on the remote computer. The command results are sent back to the local computer and appear in the Windows PowerShell session on the local computer. To transmit the commands and receive the output, Windows PowerShell uses the WS-Management protocol. For information about the WS-Management protocol, see "WS-Management Protocol" in the MSDN (Microsoft Developer Network) library at http://go.microsoft.com/fwlink/?LinkId=144634. IS WINDOWS POWERSHELL REMOTING SECURE? When you connect to a remote computer, the system uses the user name and password credentials on the local computer or the credentials that you supply in the command to log you in to the remote computer. The credentials and the rest of the transmission are encrypted. To add additional protection, you can configure the remote computer to use Secure Sockets Layer (SSL) instead of HTTP to listen for Windows Remote Management (WinRM) requests. Then, users can use the UseSSL parameters of the Invoke-Command, New-PSSession, and Enter-PSSession cmdlets when establishing a connection. This option uses the more secure HTTPS channel instead of HTTP. DO ALL REMOTE COMMANDS REQUIRE WINDOWS POWERSHELL REMOTING? No. Several cmdlets have a ComputerName parameter that lets you get objects from the remote computer. These cmdlets do not use Windows PowerShell remoting. So, you can use them on any computer that is running Windows PowerShell, even if the computer is not configured for Windows PowerShell remoting or if the computer does not meet the requirements for Windows PowerShell remoting. These cmdlets include the following cmdlets: Get-Process Get-Service Get-WinEvent Get-EventLog Get-WmiObject Test-Connection To find all the cmdlets with a ComputerName parameter, type: get-help * -parameter ComputerName To determine whether the ComputerName parameter of a particular cmdlet requires Windows PowerShell remoting, see the parameter description. To display the parameter description, type: get-help <cmdlet-name> -parameter ComputerName For example: get-help get-process -parameter Computername For all other commands, use the Invoke-Command cmdlet. HOW DO I RUN A COMMAND ON A REMOTE COMPUTER? To run a command on a remote computer, use the Invoke-Command cmdlet. Enclose your command in braces ( {} ) to make it a script block. Use the ScriptBlock parameter of Invoke-Command to specify the command. You can use the ComputerName parameter of Invoke-Command to specify a remote computer. Or, you can create a persistent connection to a remote computer (a session) and then use the Session parameter of Invoke-Command to run the command in the session. For example, the following commands run a Get-Process command remotely. invoke-command -computername Server01, Server02 -scriptblock {get-process} - OR - invoke-command -session $s -scriptblock {get-process} To interrupt a remote command, type CTRL+C. The interruption request is passed to the remote computer, where it terminates the remote command. For more information about remote commands, see about_Remote and the Help topics for the cmdlets that support remoting. CAN I JUST "TELNET INTO" A REMOTE COMPUTER? You can use the Enter-PSSession cmdlet to start an interactive session with a remote computer. At the Windows Powershell prompt, type: Enter-PSSession <ComputerName> The command prompt changes to show that you are connected to the remote computer. <ComputerName>\C:> Now, the commands that you type run on the remote computer just as though you typed them directly on the remote computer. To end the interactive session, type: Exit-PSSession An interactive session is a persistent session that uses the WS-Management protocol. It is not the same as using Telnet, but it provides a similar experience. For more information, see Enter-PSSession. CAN I CREATE A PERSISTENT CONNECTION? Yes. You can run remote commands by specifying the name of the remote computer, its NetBIOS name, or its IP address. Or, you can run remote commands by specifying a Windows PowerShell session (PSSession) that is connected to the remote computer. When you use the ComputerName parameter of Invoke-Command or Enter-PSSession, Windows PowerShell establishes a temporary connection. Windows PowerShell uses the connection to run only the current command, and then it closes the connection. This is a very efficient method for running a single command or several unrelated commands, even on many remote computers. When you use the New-PSSession cmdlet to create a PSSession, Windows PowerShell establishes a persistent connection for the PSSession. Then, you can run multiple commands in the PSSession, including commands that share data. Typically, you create a PSSession to run a series of related commands that share data. Otherwise, the temporary connection created by the ComputerName parameter is sufficient for most commands. For more information about sessions, see about_PSSessions. CAN I RUN COMMANDS ON MORE THAN ONE COMPUTER AT A TIME? Yes. The ComputerName parameter of the Invoke-Command cmdlet accepts multiple computer names, and the Session parameter accepts multiple PSSessions. When you run an Invoke-Command command, Windows PowerShell runs the commands on all of the specified computers or in all of the specified PSSessions. Windows PowerShell can manage hundreds of concurrent remote connections. However, the number of remote commands that you can send might be limited by the resources of your computer and its capacity to establish and maintain multiple network connections. For more information, see the example in the Invoke-Command Help topic. WHERE ARE MY PROFILES? Windows PowerShell profiles are not run automatically in remote sessions, so the commands that the profile adds are not present in the session. In addition, the $profile automatic variable is not populated in remote sessions. To run a profile in a session, use the Invoke-Command cmdlet. For example, the following command runs the CurrentUserCurrentHost profile from the local computer in the session in $s. invoke-command -session $s -filepath $profile The following command runs the CurrentUserCurrentHost profile from the remote computer in the session in $s. Because the $profile variable is not populated, the command uses the explicit path to the profile. invoke-command -session $s {. "$home\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"} After running this command, the commands that the profile adds to the session are available in $s. You can also use a startup script in a session configuration to run a profile in every remote session that uses the session configuration. For more information about Windows PowerShell profiles, see about_Profiles. For more information about session configurations, see Register-PSSessionConfiguration. HOW DOES THROTTLING WORK ON REMOTE COMMANDS? To help you manage the resources on your local computer, Windows PowerShell includes a per-command throttling feature that lets you limit the number of concurrent remote connections that are established for each command. The default is 32 concurrent connections, but you can use the ThrottleLimit parameters of the cmdlets to set a custom throttle limit for particular commands. When you use the throttling feature, remember that it is applied to each command, not to the entire session or to the computer. If you are running commands concurrently in several sessions or PSSessions, the number of ...
magdula294