Hi YF
kindly try the sample PowerShell script that demonstrates how to run a Windows Server 2019 backup using PowerShell 7 and an SSH remote session from a Windows 11 machine:
# Install the SSH module if not already installed
if (-not (Get-Module -Name SSHSession -ListAvailable)) {
Install-Module -Name SSHSession -Force
}
# Import the SSH module
Import-Module -Name SSHSession -Force
# Set the remote server details
$remoteServer = "ServerIP"
$remoteUsername = "Username"
$remotePassword = "Password"
# Create a new SSH session
$session = New-SSHSession -ComputerName $remoteServer -Credential (Get-Credential -UserName $remoteUsername -Password $remotePassword)
# Define the backup target location
$backupTarget = "D:\"
# Run the backup command remotely
Invoke-SSHCommand -SessionId $session.SessionId -Command "wbadmin start backup -backupTarget:$backupTarget -allCritical -quiet"
# Close the SSH session
Remove-SSHSession -SessionId $session.SessionId
Make sure to replace "ServerIP"
, "Username"
, and "Password"
with the appropriate values for your remote server.
This script first checks if the SSH module is installed and installs it if necessary. Then, it imports the SSH module and sets the remote server details.
Next, it creates an SSH session using the New-SSHSession
cmdlet, providing the remote server IP, username, and password.
The backup target location is defined using the $backupTarget
variable.
Finally, the script uses the Invoke-SSHCommand
cmdlet to run the backup command remotely on the Windows Server 2019 machine. After the backup command completes, the SSH session is closed using Remove-SSHSession
.
Please note that this script assumes you have PowerShell 7 and the SSH module installed on your Windows 11 machine. Also, ensure that you have proper permissions and follow best practices for secure remote management.