Azure Active Directory,Microsoft MD-102 Exam,Thought experiment answers Using Windows PowerShell to manage remote computers – Deploy Windows client

Using Windows PowerShell to manage remote computers – Deploy Windows client

After enabling Windows PowerShell remoting, you can use Windows PowerShell cmdlets and scripts to manage the remote computer in virtually the same way you manage local computers. However, you must first establish a connection with the remote computer.

After establishing a connection, you can run any PowerShell cmdlets or scripts against the remote machine. When you connect to the remote computer and run a remote command against it, the command is transmitted across the network and runs on the remote computer. The results are sent back to your local computer and displayed in your Windows PowerShell window.

One way to establish a remote connection and run a command is to use the invoke- command cmdlet. You can also use the invoke-command cmdlet to establish a temporary remote connection. For example, the following command retrieves the contents of the system event log from the remote computer LON-CL1.

Click here to view code image

Invoke-Command -ComputerName LON-CL1 -ScriptBlock {Get-EventLog-log system}

If you intend to run several cmdlets or more complex scripts, it is useful to establish a persistent connection to the remote computer. Use the New-PSSession cmdlet to do this. For example

Click here to view code image

$s = New-PSSession -ComputerName LON-CL1

You can now use the Enter-PSSession command to establish the persistent connection:

Enter-PSSession $s

You will now have a Windows PowerShell prompt that looks like this.

[LON-CL1]: PS C:\>

Any commands that you run in this session run on the LON-CL1 computer. The session remains active until you close with the exit-PSSession command.

You can also use these commands to establish remote connections with multiple computers. For example, use the following command to connect simultaneously to computers called LON-CL1 and LON-CL2.

Click here to view code image

$s = New-PSSession -ComputerName LON-CL1, LON-CL2

Next, run the remote Windows PowerShell cmdlets against the new session.

Click here to view code image

Invoke-Command -Session $s -ScriptBlock { Get-EventLog -logsystem }

You can run any Windows PowerShell command remotely in this way.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post