Run a Single Command

To run a command on the remote system, use the Invoke-Command cmdlet using the following syntax:

Invoke-Command -ComputerName COMPUTER -ScriptBlock { COMMAND } -credential USERNAME

“COMPUTER” represents the remote compoter's name or IP address. “COMMAND” is the command you want to run. “USERNAME” is the username you want to run the command as on the remote computer. You’ll be prompted to enter a password for the username.

Run a Script File

To run multiple commands, you can separate them with semicolons in the script block. However, a better option is to use the -FilePath option instead of the -ScriptBlock option, which allows you to execute an entire PowerShell script: