Invoke-VMscript getting object out of it

by Grzegorz Kulikowski

So have ever been tired of parsin the ScriptOutput from the Invoke-VMscript you were running on some VM object ? Right, yesterday i was shown a tiny trick that saves us tons of time, have a look.

Invoke-VMScript scriptoutput json

So you can see from the picture above that we hold now an PSCustomObject with 3 properties value,DisplayHint,DateTime. We can now cast the DateTime value to DateTime object.

We now operate on the ‘real’ DateTime object.

If we would do this with the standard approach we would have a string with the date(which can be then converted to DateTime as well).

Let’s try something more complex than a date

You can have file/directory listing , and we repeat the same thing again, we ask the script to have itself converted to json, so that in Scriptoutput we get json. Now we convert it.

And now its easy to access all the properties, no need to parse that ‘text’ that came from Scriptoutput.


You may also like

Leave a Reply

Chinese (Simplified)DutchEnglishFrenchGermanHindiPolishRussianSpanish