Uncategorized · February 6, 2021 0

Invoke

Hi this is Jaber,

Invoke lets you execute PS commands on remote computers. Probably its the most important command when it comes to automations and windows administration! I will show you some use cases

case 1, simple execution

$computerName = “someName”

Invoke-Command -ComputerName $computerName -ScriptBlock {
#some PS command
}

case 2, execute with parameters. You will use this method when you want to pass parameter from local machine to remote computer

$computerName = “someName”

$someParameter = something

Invoke-Command -ComputerName $computerName -ScriptBlock {
Param($someParameter)

#some PS command that uses the parameter
} -ArgumentList $someParameter

case 3, execute with returning. use this when you want to return a valuse that you need to be stored in some variable on your local computer

Close Bitnami banner
Bitnami