Help formatting output

This topic contains 2 replies, has 2 voices, and was last updated by  Jeremy Murrah 3 years, 8 months ago.

  • Author
  • #16541

    Jeremy Murrah

    I've got a script that gathers information for a server from a couple of different places. The cmdlets for each location return objects, and I attach those as properties for my main output object. Like this:

    PS C:\scripts> $output
    DNSARecord      : @{_ref=record:a/ZG5zLmJpbmRfYSQuX2RlZmF1bHQuY29tLmVwcm9kLHRzY
                      efault; ipv4addr=;
    DNSPTRRecord    : @{_ref=record:ptr/ZG5zLmJpbmRfcHRyJC5fZGVmYXVsdC5hcnBhLmluLWF
            ; ipv4addr=;
    LandeskAccount  : {Microsoft.PowerShell.Commands.NewWebserviceProxy.Autogenerat
                      , Microsoft.PowerShell.Commands.NewWebserviceProxy.Autogenera
    DNSCNameRecord  :
    ComputerAccount : CN=SERVERNAME,OU=SMS,OU=Test,OU=Servers,DC=eprod,DC=com

    Each of the output properties are objects themselves:

    PS C:\scripts> $output.dnsarecord
    _ref                ipv4addr            Credential          GridServer
    ----                --------            ----------          ----------
    record:a/ZG5zLmJ...       System.Managemen...
    PS C:\scripts> $output.DNSPTRRecord
    _ref                ipv4addr            Credential          GridServer
    ----                --------            ----------          ----------
    record:ptr/ZG5zL...       System.Managemen...
    PS C:\scripts> $output.LandeskAccount
    DisplayName                : SERVERNAME
    MaintenanceWindow          :
    LastVulnerabilityScanTime  : 6/26/2014 2:58:50 AM
    LastStartUpTime            : 6/24/2014 9:20:13 AM
    Type                       : Server
    OperatingSystem            : Microsoft Windows Server 2012 R2 Server Standard
                                 Edition (full installation), 64-bit
    OperatingSystemServicePack : 0
    LastHardwareScanTime       : 6/26/2014 1:04:13 AM
    Model                      : ProLiant BL460c G7
    SerialNumber               : MXQ0420X8K
    AgentConfigurationName     : ServerOps
    AgentVersion               :
    GUID                       : {2688A755-9424-EA4F-BC46-9259A378D005}
    DeviceName                 : SERVERNAME
    DomainName                 :
    LastLogin                  :
    IPAddress                  :
    SubNetMask                 :
    MACAddress                 : 68B599B1DD10
    OSName                     : Microsoft Windows Server 2012 R2 Server Standard
                                 Edition (full installation), 64-bit
    PS C:\scripts> $output.ComputerAccount
    DistinguishedName : CN=SERVERNAME,OU=SMS,OU=Test,OU=Servers,DC=eprod,DC=com
    DNSHostName       :
    Enabled           : True
    Name              : SERVERNAME
    ObjectClass       : computer
    ObjectGUID        : 7eb9f8e7-2034-4649-a310-40725d9cbacf
    SamAccountName    : SERVERNAME$
    SID               : S-1-5-21-1327060583-1562144247-1555438652-151332
    UserPrincipalName :

    Is there a way to have the output expand out all the properties for easier viewing? Maybe with a ps1xml file or something? Kind of want it to look like this:

    PS c:\scripts> $output
    DNSARecord		:_ref		:record:a/blahblah
    			:ipv4addr	:
    			:credential	:blah
    ComputerAccount	:DistinguishedName	:blah
    			:dnshostname		:servername.domain
    			:SID			:blah

    Edit: ok the above is kind of wonky in the editor, but basically just want to expand out the objects in the properties and have it all in one screen. kind of like a select-object -expandproperty * or something.

  • #16542

    Dave Wyatt

    I don't know of a way to get output like that with the built-in cmdlets. Format-Custom does display the object graph down to a certain depth (2 by default, I believe), but the formatting isn't as user-friendly.

  • #16543

    Jeremy Murrah

    ok, format-custom is pretty cool. Will have to mess around with that and see what it can do, the depth parameter gets me most of the way there. thanks!

You must be logged in to reply to this topic.