question

PraveenMittapalli-6705 avatar image
2 Votes"
PraveenMittapalli-6705 asked whoward-msft commented

Invoke-AzVMRunCommand returns a string output i want to have list of objects , is there anyway to get that

Invoke-AzVMRunCommand returns a string output i want to have list of objects , is there anyway to get that .

I am using below cmdlets to fetch the output :

$out = Invoke-AzVMRunCommand -ResourceGroupName "Test" -VMName "PraveenTestVM7" -CommandId runpowershellscript -ScriptPath C:\Users\praveen.mittapalli\Desktop\RawDiskScript.ps1 -Verbose



$finaloutput = $out.Value[0].Message

The $finaloutput is a string but i need a list of object is there anyway to get that or convert it

windows-server-powershellazure-virtual-machines
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AbhishekSingh-7599 avatar image
3 Votes"
AbhishekSingh-7599 answered whoward-msft commented

Hi you can try this as mentioned below using cs convertor to get it in usable format :

Remote script :

Get-Disk | Where-Object PartitionStyle -EQ 'RAW' | ConvertTo-Csv

Invoke script :

$out = Invoke-AzVMRunCommand -ResourceGroupName "Test" -VMName "TestVM" -CommandId runpowershellscript -ScriptPath C:\Users\Desktop\RawDiskScript.ps1 -Verbose
$s=$out.Value[0].Message
$x=$s | ConvertFrom-Csv


$x | Export-Csv -Path C:\Users\Desktop\testrawdisk.csv -NoTypeInformation

· 10
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

why you need convert something From csv if on the next line you will export it back to the csv?

0 Votes 0 ·

That's because without convertto-csv the output comes in string format which is a list of object in string format , by doing so i get it in a readable format and can convert it back to object in my invoke script

0 Votes 0 ·

i'm not saing anything about converto-csv but about convertfrom-csv
you can just execute

$out.Value[0].Message | out-file C:\Users\Desktop\testrawdisk.csv and got exact the same output

0 Votes 0 ·
Show more comments
RichMatheisen-8856 avatar image
1 Vote"
RichMatheisen-8856 answered

No, there isn't. The data are deserialized before being returned. The same is true for any cmdlet/script that's run on another machine.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
1 Vote"
IanXue-MSFT answered SinghAbhishekbr-3469 commented

Hi,

A string actually is an object of string class. What do you want $finaloutput to be like?

Best Regards,
Ian

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

the expected output is a list of azure vm disks objects but i am getting it in a string format hence not a viable format to output it in a csv ot html file

0 Votes 0 ·
VectorBCO avatar image VectorBCO SinghAbhishekbr-3469 ·

for getting azure vm disk information you have other prefferable ways like this

0 Votes 0 ·

Hi thanks for your response i already knew this azure level disk report, but in my case i need OS level raw disks hence i am using invoke cmdlet

0 Votes 0 ·
Show more comments