It appears to work and return
"ok"
"ok"
Just a couple of powershell pointers here, $lines= @() is an empty array. It's unused in your script above.
when you do $B += ... you've created a string. So if you have multiple things you're adding to $B they will be on one line. If you added both to $A or both to $B, the output would be "okok".
Since $lines is defined as an array, you can do this add both values to the array and output it once:
====script snippet====
$lines= @()
foreach ($linein$orgtxt) {
switch-wildcard ($line)
{
"*Chassis-1*" {$lines+=$line.Substring(48,2)}
"*PS-1*" {$lines+=$line.Substring(48,2)}
}
}
$lines
====script====
Oh and I took out the extra switch statement. You are only testing one variable. The Scripting Guy has a good article on it:
Windows PowerShell Tip: Using the Switch Statement I showed that to a coworker and he really liked it.
I like to use powershell_ise so I keep the script in one pane and a prompt below. I can type in the variable names and examine their output. And get more details about them by piping to get-member (gm is a shortcut for get-member).
$lines | gm