Powershell turn strings into array with headings -
i'd create table headings series of strings, have been pulled output. i've used this...
$scopearray = @("$server","$ip","$scopename","$comment")
to turn this...
$ip = $trimmed[0] $server = $trimmed[1] $scopename = $trimmed[2] $comment = $trimmed[3]
into this:
ps c:\windows\system32> $scopearray myserver.domain 10.1.1.1 nameofscope scopedetails
but need turn table, this:
i've tried below, , copule of other multidimentional examples, i'm missing fundamental.
$table = @() foreach ($instance in $scopearray) { $row = "" | select servername,ip,scopename,comment $row.heading1 = "server name" $row.heading2 = "ip address" $row.heading3 = "scope name" $row.heading4 = "comment" $table += $row }
create objects input data:
... | foreach-object { new-object -type psobject -property @{ 'server name' = $trimmed[1] 'ip address' = $trimmed[0] 'scope name' = $trimmed[2] 'comment' = $trimmed[3] } }
in powershell v3 , newer can simplify using [pscustomobject]
type accelerator:
... | foreach-object { [pscustomobject]@{ 'server name' = $trimmed[1] 'ip address' = $trimmed[0] 'scope name' = $trimmed[2] 'comment' = $trimmed[3] } }
powershell displays objects 4 properties in tabular form default (unless objects have specific formatting instructions), can force tabular output via format-table
cmdlet if required:
... | format-table
note need out-string
in addition format-table
if instance want write tabular representation file:
... | format-table | out-string | set-content 'c:\output.txt'
wiki
Comments
Post a Comment