question

ChristopherJack-1763 avatar image
0 Votes"
ChristopherJack-1763 asked RichMatheisen-8856 answered

Put Clipboard into 3dimensional array in Powershell

Hi,

In my clipboard i have

"ShipmentReference" "Name" "Attention" "Address1" "Address2" "City" "StateProv" "PostalCode" "Country" "Phone" "Email" "ServiceCode" "ShipmentInsuranceFreight" "CurrencyCode" "PackageCount" "PackageReference" "PackageWeight" "WeightUnit" "Length" "Width" "Height" "DimensionsUnit" "ItemSKU" "ItemQuantity" "ItemUnitPrice" "ItemDescription" "ItemCountryOfOrigin" "ItemHSCode" "Commercial Clearence" "VendorName" "VenderAddress1" "VendorAddress2" "VendorCity" "VendorStateProv" "VendorPostalCode" "VendorCountry""85800000000000748710" "AgnÞs AUFEVRE" "" "Street" " " "citu" "50" "'postcode" "FR" "phone" "email" "LGINTBPIP""" "EUR" "1" "85800000000000748710" "0.5010" "Kilos" "28.5" "15.5" "5" "cm" "MS25356" "1.000" "29.13" "Product" "CN" "7117190090" "" "company name " "street" "Chalgrove " "Oxfordshire" "" "'postcode" "GB"

From $DataSetTable | ConvertTo-Csv -NoType -Del "t" | Clip;`

If I call

 $comps = (Get-Clipboard).Split("`t");
 Write-Host $comps [0];

I get

ShipmentReference

If I call

 $comps = (Get-Clipboard).Split("`n")
 Write-Host $comps [0];

I get

"ShipmentReference" "Name" "Attention" "Address1" "Address2" "City" "StateProv" "PostalCode" "Country" "Phone" "Email" "ServiceCode" "ShipmentInsuranceFreight" "CurrencyCode" "PackageCount" "PackageReference" "PackageWeight" "WeightUnit" "Length" "Width" "Height" "DimensionsUnit" "ItemSKU" "ItemQuantity" "ItemUnitPrice" "ItemDescription" "ItemCountryOfOrigin" "ItemHSCode" "Commercial Clearence" "VendorName" "VenderAddress1" "VendorAddress2" "VendorCity" "VendorStateProv" "VendorPostalCode" "VendorCountry"

I want to be able put that into a 3dimensional array so I can say
[1,1] is "ShipmentReference"
[1,2] is "Name"
[2,1] is "AgnÞs AUFEVRE"

What is the best way of going about this. I have tried to reference the table itself without copying to clipbaord but that doersnt work so found tbhe only way to see the data is to copy the table to the clipboard.

Any help appreciated.















windows-server-powershellwindows-sysinternals-pstools
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

Have you tried this:

 $csv = $Dataset | ConvertTo-CSV

BTW, the example you gave isn't a 3-dimensional array, it's a 2-dimensional array.

Once you've converted the dataset you'll have an array of PSCustomObjects. Instead of referencing the individual elements by using two integers (row and column) you can refer to them by using the row as an integer and the individual properties by name (e.g. $csv[0].Name). Or you can pipe the $csv variable into a Foreach-Object loop and just reference them as $_.Name.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.