0
0
PowerShellscripting~30 mins

SSH-based remoting (PowerShell 7+) - Mini Project: Build & Apply

Choose your learning style9 modes available
SSH-based remoting with PowerShell 7+
📖 Scenario: You want to run commands on a remote computer using PowerShell 7 or newer. This is useful when you manage servers or other computers from your own machine. SSH-based remoting lets you connect securely and run commands as if you were sitting at the remote computer.
🎯 Goal: Learn how to set up a simple SSH session in PowerShell 7+, run a command remotely, and see the output on your local computer.
📋 What You'll Learn
Create a variable with the remote computer name
Create a variable with the username for SSH login
Use New-PSSession with SSH transport to connect
Use Invoke-Command to run a command remotely
Display the output of the remote command
💡 Why This Matters
🌍 Real World
System administrators often need to manage multiple servers remotely. SSH-based remoting in PowerShell 7+ lets them run commands securely without logging in physically.
💼 Career
Knowing how to use SSH remoting with PowerShell is valuable for IT professionals, DevOps engineers, and anyone managing Windows or Linux servers remotely.
Progress0 / 4 steps
1
Set up remote computer and username variables
Create a variable called $remoteComputer and set it to the string "server01.example.com". Then create a variable called $userName and set it to the string "adminuser".
PowerShell
Need a hint?

Use = to assign strings to variables. Strings go inside double quotes.

2
Create an SSH PowerShell session
Using the variables $remoteComputer and $userName, create a new PowerShell session called $session using New-PSSession with the -HostName parameter set to $remoteComputer, the -UserName parameter set to $userName, and the -SSHTransport switch.
PowerShell
Need a hint?

Use New-PSSession with the parameters exactly as shown. The -SSHTransport switch enables SSH remoting.

3
Run a remote command using the session
Use Invoke-Command with the -Session parameter set to $session to run the command hostname on the remote computer. Save the result in a variable called $remoteHostName.
PowerShell
Need a hint?

Use Invoke-Command with -Session and a script block containing hostname.

4
Display the remote hostname output
Print the value of the variable $remoteHostName to show the remote computer's hostname.
PowerShell
Need a hint?

Use Write-Output to print the variable. The output should be the hostname of the remote computer, which is server01.