Share via

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

Praveen Mittapalli 36 Reputation points
2020-11-02T12:44:28.72+00:00

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

Azure Virtual Machines
Azure Virtual Machines

An Azure service that is used to provision Windows and Linux virtual machines.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author

Abhishek Singh 381 Reputation points
2020-11-03T12:36:23.783+00:00

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

Was this answer helpful?

3 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2020-11-03T03:45:23.033+00:00

    Hi,

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

    Best Regards,
    Ian

    Was this answer helpful?

    1 person found this answer helpful.

  2. Rich Matheisen 48,116 Reputation points
    2020-11-02T15:36:13.347+00:00

    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.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.