Updates
recent

How Invoke-Command works

To know how Invoke-Command works remotely check the below image :





Apart from this, lets talk more about Invoke-Command.

  • If you run invoke-command locally will this DeSerialization, conversion to XML etc will happen? the answer is NO. Since you are running it locally all this process are not performed.
  • Further a Deserialized object Type i.e. the data fetched remotely through invoke-command contains only few methods as shown in the below image. Hence suppose you are fetching service info using invoke-command remotely and storing the output in a variable, you won’t get methods to Start or Stop the service.


Example :

$Service = Invoke-Command -Cn “Test” -ScriptBlock {get-service bits}

$Service will show the process details, but you can’t perfom $Service.Stop() or $Service.Start() since its the deserialized data.

But you can perform like this :

$Service = Invoke-Command -Cn “Test” -ScriptBlock {get-service bits | Stop-Service}

This will do the task you are looking for.


Hope you all liked the Post. Do Like and Share with your friends
Copyright © 2016 Amar Helloween. Powered by Blogger.