azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

AzureRM cmdlets return object with a json-like format

Open trondhindenes opened this issue 11 years ago • 65 comments

When running for example Get-AzureRmVm, the following is returned: image For some reason the Azure team decided to go with a "json-like" view of returned objects, making it incredibly hard to read the output - json is simply a bad choice for being consumed by humans.

Implement proper output objects by using PowerShell formatting file (.format.ps1xml).

trondhindenes avatar Dec 01 '15 08:12 trondhindenes

hear! hear! I am astonished at the non-PowerShellness of the new AzureRM cmdlets. I also wonder when I will be able to create a container? Luke

From: trondhindenes Sent: Tuesday, December 1, 2015 7:52 PM To: Azure/azure-powershell Subject: [azure-powershell] AzureRM cmdlets return object with a json-like format (#1384)

When running for example Get-AzureRmVm, the following is returned:

For some reason the Azure team decided to go with a "json-like" view of returned objects, making it incredibly hard to read the output - json is simply a bad choice for being consumed by humans.

Implement proper output objects by using PowerShell formatting file (.format.ps1xml).

— Reply to this email directly or view it on GitHub.

lukeb1961 avatar Dec 01 '15 09:12 lukeb1961

"json is simply a bad choice for being consumed by humans"

Not to mention that nothing in the PowerShell core sets a precedent like this for displaying objects.

Cheers, Trevor Sullivan

pcgeek86 avatar Dec 01 '15 23:12 pcgeek86

Honestly I think it's just in how they decided to format the output, to lead folks in the direction of templates.

jeffpatton1971 avatar Dec 02 '15 19:12 jeffpatton1971

@jeffpatton1971 don't you agree that the output is terrible? I'm finding the spacing, characters and commas increidble hard to read. If it's too hard to implement format.psxml files, just give me regular objects. Like every other PS module on the planet does.

trondhindenes avatar Dec 07 '15 13:12 trondhindenes

Let me answer this way. Using the image you posted above, what you see is what appears to be json output for the extensions property. For me, I kind of like being able to see (at a glance) all the properties and values in the underlying object; it's nice. My problem with this view is that the data being displayed is most likely held in ExtensionsText property (https://gist.github.com/jeffpatton1971/29e536cd0147694796cd) this is misleading at best, an outright lie at worst. I still feel this is a silly formatting issue.

from your perspective and that of someone who has been building custom powershell modules for my employers for years now, I feel like you. Seriously Microsoft? In every single blessed example of powershell on Microsoft.com and beyond this is not a thing. do not start altering the formatting like this for arbitrary cmdlets on what appear to be arbitrary modules within the overarching azure powershell library...it's stupid.

jeffpatton1971 avatar Dec 07 '15 14:12 jeffpatton1971

Adding folks from the dev team and networking team as well @huangpf @hyonholee @DeepakRajendranMsft since this is prevalent in both Compute and Networking cmdlets.

Definitely good feedback. One thing I am yet to see the alternative to a JSON format that is good at displaying properties that are n levels deep. For example how to display all the information in a StorageProfile array of data disks

StorageProfile           : {
                         "DataDisks": [
                           {
                             "Lun": 0,
                             "Caching": "ReadWrite",
                             "CreateOption": "Empty",
                             "DiskSizeGB": 1,
                             "Name": "data-disk-1",
                             "SourceImage": null,
                             "VirtualHardDisk": {
                               "Uri": "http://123.blob.core.windows.net/vhds/data-disk-1.vhd"
                             }
                           },
                           {
                             "Lun": 1,
                             "Caching": "ReadWrite",
                             "CreateOption": "Empty",
                             "DiskSizeGB": 1,
                             "Name": "data-disk-2",
                             "SourceImage": null,
                             "VirtualHardDisk": {
                               "Uri": "http://123.blob.core.windows.net/vhds/data-disk-2.vhd"
                             }
                           }
                         ],

I'm not saying it is the best way to display information but I'm trying to find an approach that strikes a balance between users who want to see all information in one place and users who don't appreciate all the brackets, quotes. If we went with a more YAML like approach, is that acceptable?

Attached is a sample image

singhkays avatar Dec 08 '15 19:12 singhkays

Just copying this over the yammer feed.

Honestly, I think just not display the text fields in the output is fine. The typical output of .net properties in powershell is really very simple. I've updated my gist (https://gist.github.com/jeffpatton1971/29e536cd0147694796cd) so you can see it. Since the beginning .net objects have appeared as their type names (ie line 57 LinuxConfiguration) and in powershell we know that we can delve into that further with $vm.osprofile.linuxconfiguration to see the properties with the object. This has been the standard that Trond Hindenes has been referring to, really I think since monad. The seemingly arbitrary change to display the .net assembly as json is jarring...to say the least.

That said, I get your point, you now have easy access to view all classes and subclasses and properties...nifty..works well for looking at possibly how a template should be laid out....but again...really goes against the grain.

wwjd what would https://twitter.com/jsnover do ;-)

jeffpatton1971 avatar Dec 08 '15 21:12 jeffpatton1971

Re-reading your statement above @singhkay and I think you're trying to solve a problem, that for those of us who use powershell day in and day out, that isn't really a problem. Was this something that was discussed only internally?

Just going to re-iterate I really think this just a formatting issue, change the output format back to the traditional powershell way and be done. Then either override the .ToString() method of the objects to return json, or give param -asJson to your cmdlet.

jeffpatton1971 avatar Dec 08 '15 21:12 jeffpatton1971

If a user wants JSON output, then they pipe the VM object into ConvertTo-Json (PowerShell 3.0+).

I think that the recommendation from @singhkay is reasonable. At least it doesn't have all the syntactical details included in it. It still looks a bit messy, but for the time being, I don't have any better suggestions, unless someone else chimes in with an idea.

ps. I strongly recommend against adding an -AsJson parameter. There is no precedent in PowerShell for this, and users should be guided to use ConvertTo-Json. If someone isn't using PowerShell 3.0, or later, by now, they should be guided to upgrade.

Cheers, Trevor Sullivan

pcgeek86 avatar Dec 12 '15 21:12 pcgeek86

@pcgeek86 Adding to this from the Yammer convo

The current proposed default view is to show the below object view and show the current full detailed view using a -Full switch. However, as you can see a bunch of very useful information is hidden behind the object types which could cause a bunch of dissatisfaction from users who are now used to seeing this information in top level without using the -Full switch. So, getting a consensus on this from the community would be great!

Another question, is there a reason (other than this being the PS way) why some might prefer this view over -Full being the default view if you can access objects like $vm.OSProfile, $vm.NetworkProfile in both views?

Get-AzureRmVM -ResourceGroupName somerg -Name MyWindowsVM

ResourceGroupName : somerg
Id : /subscriptions/123431-2de6-4179-8ab1-365da4211af4/resourceGroups/somerg/providers/Microsoft.Compute/virtualMachines/MyWindowsVM
Name : MyWindowsVM
Type : Microsoft.Azure.Management.Compute.Models.VirtualMachineListResponse
Location : westus
Tags : {}
AvailabilitySetReference : null
DiagnosticsProfile : Microsoft.Azure.Management.Compute.Models.DiagnosticsProfile
Extensions : Microsoft.Azure.Management.Compute.Models.Extensions
HardwareProfile : Microsoft.Azure.Management.Compute.Models.HardwareProfile
InstanceView : null
NetworkProfile : Microsoft.Azure.Management.Compute.Models.NetworkProfile
OSProfile : Microsoft.Azure.Management.Compute.Models.OSProfile
Plan : null
ProvisioningState : Succeeded
StorageProfile : Microsoft.Azure.Management.Compute.Models.StorageProfile

singhkays avatar Dec 14 '15 22:12 singhkays

I agree with @pcgeek86 if the underlying .net is sound, then convertto-json will allow us to see that if we want to, we can also access through the typename.class.propertyname syntax.

@singhkay The useful information isn't hidden, it's there and for those of us who have been using powershell since it started, this is what we're used to and have come to expect.

Again, respectfully, I think you're trying to solve a problem that isn't.

jeffpatton1971 avatar Dec 14 '15 22:12 jeffpatton1971

@singhkay I seriously find json messy to read. In addition, what Jeff/Trevor wrote. Please look at previous unfortunate decisions the Azure PowerShell team has made in terms of diverging from the regular way of doing PowerShell and take some learning from it.

trondhindenes avatar Dec 14 '15 22:12 trondhindenes

I think users should become familiar with the object model of a Virtual Machine. If you display all of the content on the top-level VM object, then people will think that it's a more or less "flat" structure. Instead, if you require them to "drill down" into the VM object, using properties, then they will naturally learn the structure of the object. This isn't too different from other object models, such as the System.Diagnostics.Process object that is returned from the out-of-box Get-Process command.

Cheers, Trevor Sullivan

pcgeek86 avatar Dec 15 '15 01:12 pcgeek86

What is the status on this issue? Could we look forward for a regular output from powershell cmdlets as against a JSON view anytime soon? ConvertTo-Json exists anyway in case we need the output to be in JSON format.

Vijayaraghavanl avatar Dec 31 '15 09:12 Vijayaraghavanl

Update on this, we discussed this with few other teams besides Compute and the consensus is to not adopt the object view of the Get cmdlets properties as it hides too much important information e.g. below

DiagnosticsProfile : Microsoft.Azure.Management.Compute.Models.DiagnosticsProfile
Extensions : Microsoft.Azure.Management.Compute.Models.Extensions
HardwareProfile : Microsoft.Azure.Management.Compute.Models.HardwareProfile

Now on the the proposed solution. We discussed with the PowerShell team, who suggested we take a look at output of the following PS cmd which displays an object on the second level.

(Get-Process).Modules[0] | fl ModuleName,FileVersionInfo

ModuleName      : ApplicationFrameHost.exe
FileVersionInfo : File:             C:\WINDOWS\system32\ApplicationFrameHost.exe
                  InternalName:     Application Frame Host
                  OriginalFilename: ApplicationFrameHost.exe
                  FileVersion:      10.0.10586.0 (th2_release.151029-1700)
                  FileDescription:  Application Frame Host
                  Product:          Microsoft® Windows® Operating System
                  ProductVersion:   10.0.10586.0
                  Debug:            False
                  Patched:          False
                  PreRelease:       False
                  PrivateBuild:     False
                  SpecialBuild:     False
                  Language:         English (United States)

Based on this we have two designs for you folks to consider. Note in both cases you'll still be able to access subobjects the same way you do today i.e. $vm.StorageProfile.osDisk.osType

Proposal 1

  • Top level properties (profiles) and sub objects (osDIsk, imageReference, dataDisks) are aligned along a single column
  • All values within an object are aligned to a single column top to bottom for readability but values across different objects would be aligned across different column.
  • Properties that are arrays are represented with []
  • Empty line after objects to separate out the objects from other objects for readability
ResourceGroupName        : kayrg2
Id                       : /subscriptions/XXXXXXXXX/resourceGroups/kayrg2/providers/Microsoft.Compute/virtualMachines/cid4085b9ab28112a1
Name                     : cid4085b9ab28112a1
Type                     : Microsoft.Compute/virtualMachines
Location                 : westus
ProvisioningState        : Succeeded
HardwareProfile          : vmSize : Standard_D2
Tags                     : [
                            Department : testdep
                            CostCenter : testcost
                            TestTag3   : test
                           ]

AvailabilitySetReference : null
NetworkProfile           : networkInterfaces : [
                              primary : true
                              id      : /subscriptions/XXXXXXXX/resourceGroups/kayrg2/providers/Microsoft.Network/networkInterfaces/gateway-nic
                           ]

OSProfile                : computerName         : cid4085b9ab28112a1
                           adminUsername        : notused
                           adminPassword        : null
                           customData           : IyEvYmluL2Jhc2g=
                           windowsConfiguration : null
                           linuxConfiguration   :
                              disablePasswordAuthentication : false
                              ssh                           : null
                           secrets : []

Plan                     : name          : sg-byol
                           publisher     : checkpoint
                           product       : check-point-r77-10
                           promotionCode : null

StorageProfile           : imageReference :
                             publisher : checkpoint
                             offer     : check-point-r77-10
                             sku       : sg-byol
                             version   : latest

                           osDisk :
                             osType             : Linux
                             encryptionSettings : null
                             name               : osDisk
                             image              : null
                             caching            : ReadWrite
                             createOption       : FromImage
                             diskSizeGB         : null
                             vhd:
                               uri : http://ci21c713ff5add7e76.blob.core.windows.net/vhds/cid4085b9ab28112a1.vhd

DiagnosticsProfile       : bootDiagnostics :
                              enabled    :    true
                              storageUri : http://ci21c713ff5add7e76.blob.core.windows.net

Proposal 2

  • This is based on aligning all the values on a single column so that it's easier to read from top to bottom as the values are in the same line
  • The properties/keys on the left and subobjects on the left are also aligned along a single column
  • The indendtation is along the properties. These are indented according to their depth in the object
Id                              :/subscriptions/XXX/resourceGroups/ws2016/providers/Microsoft.Compute/virtualMachines/ws2016
ProvisioningState               : Succeeded
Name                            : ws2016
Location                        : westus
Type                            : Microsoft.Compute/virtualMachines

HardwareProfile:
    Size                        : Standard_D2_v2

StorageProfile:
  Imagereference:
    Publisher                   : MicrosoftWindowsServer
    Offer                       : WindowsServer
    Sku                         : Windows-Server-Technical-Preview
    Version                     : latest

  OSDisk:
    OSType                      : Windows
    Name                        : ws2016
    Caching                     : ReadWrite
    CreateOption                : FromImage
    Vhd:
      Uri                       : https://wsa89.blob.core.windows.net/vhds/ws2016sa1162616.vhd

OSProfile:
  ComputerName                  : ws2016
  UserName                      : kay
  WindowsConfiguration:
    ProvisionVMAgent            : true
    Enableautomaticupdates      : true

NetworkProfile:
  NetworkInterfaces:
    NetworkInterface #1:
      Primary                   : false
      Provisioning State        : Succeeded
      Name                      : ws2016562
      Location                  : westus

singhkays avatar Feb 11 '16 02:02 singhkays

I vote for proposal 1.

Cheers, Trevor Sullivan

pcgeek86 avatar Feb 11 '16 15:02 pcgeek86

Thanks for the feedback @pcgeek86! @trondhindenes @jeffpatton1971 @Vijayaraghavanl @lukeb1961 Any thoughts on which proposal you prefer?

singhkays avatar Mar 07 '16 18:03 singhkays

Proposal #2 is better, because the semi colons are aligned, and sub-fields at various levels are clearly indented.

Proposal #1’s semi colons are scattered all around, which makes it very difficult to follow the content, and it’s unclear when it goes to next level and when it’s not, i.e. • HardwareProfile : vmSize : Standard_D2 vs. • StorageProfile : imageReference : publisher : checkpoint

huangpf avatar Mar 11 '16 06:03 huangpf

+1 for proposal #2, but as someone who lives in PoSh with these cmdlets, I'm not sure there's a big problem with the current json output. For some reason this has never bit me when manipulating objects json output or not.

Kraftwerx avatar Mar 15 '16 21:03 Kraftwerx

Not sure why you couldn't just have the output in nested Hashtables as that really is simple enough and is already widely known.

Again its items like this that make me wonder about the decision points being made on the development practises of this set of Microsoft "Official" Modules

An example of this in action would be the objects output from the Find-Module Cmdlet and In my Opinion this is the correct way for you to output data as it can easily be manipuated and pushed along the pipeline (if required)

kilasuit avatar Mar 16 '16 15:03 kilasuit