Trying to create a list of delivery addresses for UPS. This consists of data returned from our order system, in the form of
ID
AddressFullNames
AddressLine1
AddressLine2
AddressLine3
PostalCode
I created a custom object to pull in data from other objects that are returned from our order system API .
$Delivery = New-Object -TypeName PSObject -Property @{
ID = $PBOrder.Response.ID
AddressFullNames = $BPOrder.Response.Parties.Delivery.AddressFullNames
AddressLine1 = $BP{Order.Response.Parties.Delivery.AddressLine1
AddressLine2 = $BPOrder.Response.Parties.Delivery.AddressLine2
AddressLine3 = $BPOrder.Response.Parties.Delivery.AddressLine3
PostalCode = $BPOrder.Response.Parties.Delivery.PostalCode
}
The data structure that is returned is a custom system object. which when printed out looks like this
PS> $DELIVERY
ID : {68, 69, 70, 71…}
AddressFullNames : {$null, $null, $null, $null…}
AddressLine1 : {237 Commerce St. Suite 101, PO 58, 237 Commerce St. Suite 101, PO 58…}
AddressLine3 : {, Saxeville, , Saxeville…}
PostalCode : {, R0H 0M0, , R0H 0M0…}
AddressLine2 : {Wiiliston VT 05495, , Wiiliston VT 05495, …}
I can access any of the items individual using dot notation.
For example
C:>PS $Delivery.PostalCode #But this prints out all of the postal codes.
05495
R0H 0M0
R0H 0M0
S1 4RT
R0H 0M0
54976
Of course, what I want is a regular address records that look like this.
ID : 70
AddressFullNames : Joe Blow
AddressLine1 : 123 Anywhere Lane
AddressLine2 : Sometown
AddressLine3 : VT
PostalCode : 05446
ID : 72
AddressFullNames : Mary Smith
AddressLine1 : 18 Oak Street
AddressLine2 : Nyack
AddressLine3 : NY
PostalCode : 20342
Ultimately, I want to convertto-CSV to have this as a CSV File which I can then import into my UPS shipping program.
I tried various ForEach-Object… but don’t know if you can actually nest those? So, if an object contains strings fields and fields that are hash tables… how would you print out the string field and the hash table field in a coherent record, where
PS>$customer= @{Name=“Davy Jones”; Delivery=@{Company=“BigCorp”; Address=“123 Corporate Lane”; City=“Gotham”; State=“NY”; Zip=“03232”}}
PS>
Name Value
Delivery {Zip, State, Company, Address…}
Name Davy Jones
I’m missing something here…
Thanks.