Saturday, 7 January 2017

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

No comments:

Post a Comment

Hyperlinks are not allowed in comments, Spam/advertising comments will NEVER BE TOLERATED and will be deleted immediately!

Thanks for visiting our website,Bookmark us for more updates.

Contact us


Email *

Message *