Put Clipboard into 3dimensional array in Powershell

Christopher Jack 1,611 Reputation points
2021-02-04T16:20:21.757+00:00

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 PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,387 questions
Sysinternals
Sysinternals
Advanced system utilities to manage, troubleshoot, and diagnose Windows and Linux systems and applications.
1,095 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 45,096 Reputation points
    2021-02-04T19:49:14.243+00:00

    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.

    0 comments No comments