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.
7,160 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
0 comments No comments
{count} votes

Accepted answer
  1. 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

    3 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Rich Matheisen 45,091 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.

    1 person found this answer helpful.
    0 comments No comments

  2. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,971 Reputation points Microsoft Vendor
    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

    1 person found this answer helpful.