lundi 24 juillet 2017

Construct a custom object whose properties will be enumerated in the order in which they were defined

I have an object that I created in PowerShell to fetch info from AWS.

$list = New-Object -TypeName PSObject -Property @{
  'name'          = ($instance.Tags | Where-Object {$_.Key -eq 'Name'}).Value
  'baseAmi'       = ""
  'patchDate'     = ""
  'baseName'      = ""
  'owner'         = ($instance.Tags | Where-Object {$_.Key -eq 'Owner'}).Value
  'instanceID'    = $instance.InstanceID
  'imageID'       = $instance.ImageId
  'env'           = ($instance.Tags | Where-Object {$_.Key -eq 'EnvName'}).Value
  'instanceState' = $instance.State.Name
}
$baseAmi = Get-EC2Image -ImageId $list.imageID
$list.baseAmi = ($baseAmi.Tags | Where-Object{$_.Key -eq 'BaseAmi'}).Value
$baseAmi = Get-Ec2Image -ImageId $list.baseAmi
$list.patchDate = ($baseAmi.Tags | Where-Object{$_.Key -eq 'PatchDate'}).Value
$list.baseName = ($baseAmi.Tags | Where-Object{$_.Key -eq 'Name'}).Value

I would like to output the fields of the object in the following order:

baseName,baseAmi,patchDate,name,owner,instanceID,env,instanceState

This object is then exported as a CSV. I basically need the CSV headers to be organized in that order when viewing it in Excel.





Aucun commentaire:

Enregistrer un commentaire