Skip to main content

Execute a PowerShell script and commands on a remote computer/host using the invoke command.

Invoke-Command -ComputerName REMOTE_COMPUTER_NAME -ScriptBlock {
    # To create a directory on the remote server:
    New-Item C:\local\path\on\remote\computer -type directory -Force

    # To delete a directory on the remote server:
    Remove-Item C:\local\path\on\remote\computer -Force
}