Saturday, July 23, 2016

PowerShell remoting

If you've ever needed to run a command on a remote computer, you've probably used PsExec. I've done that, but I've found something better that comes with Windows: PowerShell's remoting capabilities. Once the firewall is configured to allow remote management, you can use Invoke-Command to run a script block at a remote machine and get the output as a PowerShell object.

Invoke-Command -ComputerName 'example' {gci C:\}

Invoke-Command {type $file} -ComputerName $hostname -Credential (New-Object PSCredential -ArgumentList 'username', (ConvertTo-SecureString 'password' -AsPlainText -Force))

No comments:

Post a Comment