Share via


Remove brackets in the array results

Question

Tuesday, September 18, 2012 5:01 PM

Hello everyone,

I have basic script that i get data from csv file;

$Sstatus = Import-Csv C:\Services.csv
$Sstatus | Select-String -Pattern "server01"

@{ServerName=server01.ABC.LCL; Status=OK}

as you can see in the results PowerShell adds @{ signs. Is there way to remove that from the results and display the result just like the below.

ServerName=server01.ABC.LCL; Status=OK

Thank you.

EverydayLearner

All replies (6)

Tuesday, September 18, 2012 5:37 PM ✅Answered

The best I can come up with involves a bit of manipulation:

$Sstatus | Select-String -Pattern "server01" | % { ($_ | Out-String).Trim() -replace '@\{|\}' }

Grant Ward, a.k.a. Bigteddy


Tuesday, September 18, 2012 5:41 PM ✅Answered

(get-content C:\Services.csv) -match 'Server01' | foreach {'ServerName={0};Status={1}' -f $_.split(',')}

[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


Tuesday, September 18, 2012 5:43 PM ✅Answered

here is what i came up with added another variable

$a = $Sstatus | Select-String -Pattern "server01"$c = $a.ToString().trimstart("@{").trimend("}")Not sure if it is best way to do it but it looks like it is working OK for now. 

EverydayLearner


Tuesday, September 18, 2012 5:14 PM

Try this:

$Sstatus | Select-String -Pattern "server01" | select -exp line

Grant Ward, a.k.a. Bigteddy


Tuesday, September 18, 2012 5:20 PM

unfortunately it did not change the result.

EverydayLearner


Tuesday, September 18, 2012 5:58 PM

Thank you very much both of you.

EverydayLearner