Hello world!
I’m completely newbie in Powershell and i need your help …
I created 3 variables containing values separated by “;” :
$process = processname
$Sresult = Sdata1;Sdata2;Sdata3;Sdata4;Sdata5 …
$Iresult = Idata1;Idata2;Idata3;Idata4;Idata5 …
I would like to have an array or hash table like this (i don’t know what is the best solution) :
Process Sresult Iresult
processname Sdata1 Idata1
processname Sdata2 Idata2
and so on … at the end of course a small CSV output is planned. …
Thanks !
Olaf
April 12, 2017, 4:18am
2
It might be helpful to know how you created this variables. It might be easier to create what you’re looking for directly in the process of getting the information than stitching it together afterwards. (sorry for my poor english)
Hi Olaf
I retrieve these values from a complex xml-like file with several tags with a regex … these tags don’t have any ID …
e.g. :
suppliers
COM-09 To perform Operative Planning
inputs
Validated Operative Plan (full view & Cascaded)
I use this “really-dirty” foreach loop to parse all the lines :
# Retrieve the Suppliers
"**************** Suppliers **************************"
$pattern = "(?:)(.*)(?:)"
foreach ($suppliers in $XmlDocument.metadata.entry.map.entry.map.entry)
{
if ($suppliers.string -eq "suppliers")
{
$result = [Regex]::Match($suppliers.string, $pattern)
$Sresult = $Sresult += $result.Value.replace('','').replace('','')
$Sresult = $Sresult -replace "&","&"
$Sresult = $Sresult + ";"
}
if ($suppliers.string -eq "inputs")
{
$result = [Regex]::Match($suppliers.string, $pattern)
$Iresult = $Iresult += $result.Value.replace('','').replace('','')
$Iresult = $Iresult -replace "&","&"
$Iresult = $Iresult + ";"
}
}
#region Input
$Process = 'one','two','three'
$Color = 'green','blue','yellow'
$Memory = 2,4,8
#endregion
#region Process
# Put them in a Powershell Object:
$myOutput = 0..2 | foreach {
[PSCustomObject]@{
Process = $Process[$_]
Color = $Color[$_]
Memory = $Memory[$_]
}
}
#endregion
#region Output
$myOutput | Format-Table -AutoSize # output to console
$myOutput | Out-GridView # output to ISE gridview
$myOutput | Export-Csv .\mystuff.csv -NoTypeInformation # dump to CSV
#endregion
For more information on arrays see this article …