What is Import PSSession in Powershell
Run remote commands
- 3 minutes to read
You can run commands on one or hundreds of computers with a single PowerShell command. Windows PowerShell supports remote computing using a variety of technologies, including WMI, RPC, and WS-Management.
PowerShell Core supports WMI, WS management, and SSH remoting. PowerShell 6 no longer supports RPC. As of PowerShell 7, RPC is only supported in Windows.
For more information about remoting in PowerShell Core, see the following articles:
Windows PowerShell remoting without configuration
Many Windows PowerShell cmdlets have a ComputerName parameter that you can use to collect data from one or more remote computers and make settings changes. These cmdlets use different communication protocols and work on all Windows operating systems without special configuration.
These cmdlets include:
Typically, cmdlets that support remoting without any special configuration have the "ComputerName" parameter rather than the "Session" parameter. To find these cmdlets in your session, type:
Windows PowerShell remoting
Using the WS-Management protocol, you can use Windows PowerShell Remoting to run any Windows PowerShell command on one or more remote computers. You can create persistent connections, start interactive sessions, and run scripts on remote computers.
To use Windows PowerShell remoting, the remote computer must be configured for remote administration. For more information and instructions, see Understanding Remote Requirements.
After you've configured Windows PowerShell remoting, there are many remoting strategies available to you. Only a few of them are listed in this article. For more information, see About Remote.
Start an interactive session
To start an interactive session with a single remote computer, use the Enter-PSSession cmdlet. For example, to start an interactive session with the remote computer "Server01", enter:
The prompt changes to show the name of the remote computer. Any commands you enter at the command prompt will be run on the remote computer and the results will be displayed on the local computer.
To end the interactive session, enter:
For more information about the Enter-PSSession and Exit-PSSession cmdlets, see:
Run a remote command
To run a command on one or more computers, use the Invoke-Command cmdlet. For example, to run a Get-UICulture command on remote computers Server01 and Server02, you would type:
The output is returned to the computer.
Run a script
To run a script on one or more remote computers, use the FilePath parameter of the cmdlet. The script must be on or available to the local computer. The results are returned to the local computer.
For example, the following command runs the DiskCollect.ps1 script on remote computers Server01 and Server02.
Establish a permanent connection
Use the cmdlet to create a persistent session on a remote computer. The following example creates remote sessions on Server01 and Server02. The session objects are saved in the variable.
Now that the sessions are established, you can run any command in them. And because the sessions are permanent, you can collect data from one command and use it in another command.
For example, the following command executes a Get-HotFix command in the sessions in the $ s variable and then saves the results in the $ h variable. The "$ h" variable is created in "$ s" in each of the sessions, but does not exist in the local session.
You can now use the data in the variable with other commands in the same session. The results are displayed on the local computer. Example:
These are just the basic capabilities that Windows PowerShell remotely offers. Using cmdlets installed with Windows PowerShell, you can set up and configure remote sessions both locally and remotely, create custom and restricted sessions, and allow users through a remote session to import commands that are actually implicitly executed in the remote session configure the security of a remote session, and much more.
Windows PowerShell includes a WSMan provider. The provider creates a drive that allows you to navigate through a hierarchy of configuration settings on the local computer and on the remote computers.
For more information about the WSMan provider, see WS-Management Providers and WS-Management Cmdlets Information. Alternatively, enter in the Windows PowerShell console.
Further information can be found in the following sources:
For help with remoting errors, see about_Remote_Troubleshooting.
- Why do the Chinese call China a democracy
- Why did India adopt western culture
- What are the advantages of DBMS
- Has any foreigner visited every Indian state
- Who are the Roma
- Who interviews and hires the CEO
- Can someone with ADD really have Asperger's
- How does Starbucks pay its suppliers
- Why do people get stupid and materialistic
- Can a man live without marriage
- Is digital marketing the best career option
- J Cole falls out
- Which tea has the most benefits
- What is special about Uluru in Australia
- Is China corrupt
- What is the best diamond
- Who am I in a spiritual sense
- What schools teach Chinese language in Mexico
- How are the police in Kerala
- Should the government support the lottery
- What is your unique life lesson
- Why are people against Manu Smriti
- How can a boy attract a girl
- How hard is it to learn ASL