Hello,
Let's see if someone can help me out with this powershell script I am trying to write..
I have a $variable containing hundreds of lines (below you can see an example how it looks like)
I need to save different lines in different variables following some pattern like this.
(white spaces) + MPS + lpgp*
(white spaces) + MPS + lpnz*
(white spaces) + MPS + lpgb* ...
I am trying to do something like
$variable | % { if ($_ -match "MPS LPGP*") {$lpgp += $_ }}
But it doesnt work
.....
MPS lpgpctx0001 MPS MPS_PLT_2005.0427 (v1.0) (lpgpctxli0002/27000 30705), start Tue 6/29 15:12 MPS lpnzctx0001 MPS MPS_PLT_2005.0427 (v1.0) (lpgpctxli0002/27000 30705), start Tue 6/29 15:12....
Users of MPS_ENT_CCU: (Total of 10 licenses issued; Total of 0 licenses in use)
Thank you!
trying to match lines and assign to variable
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
trying to match lines and assign to variable
Hello,
Let's see if someone can help me out with this powershell script I am trying to write..
I have a $variable containing hundreds of lines (below you can see an example how it looks like)
I need to save different lines in different variables following some pattern like this.
(white spaces) + MPS + lpgp*
(white spaces) + MPS + lpnz*
(white spaces) + MPS + lpgb* ...
I am trying to do something like
$variable | % { if ($_ -match "MPS LPGP*") {$lpgp += $_ }}
But it doesnt work
.....
MPS lpgpctx0001 MPS MPS_PLT_2005.0427 (v1.0) (lpgpctxli0002/27000 30705), start Tue 6/29 15:12 MPS lpnzctx0001 MPS MPS_PLT_2005.0427 (v1.0) (lpgpctxli0002/27000 30705), start Tue 6/29 15:12....
Users of MPS_ENT_CCU: (Total of 10 licenses issued; Total of 0 licenses in use)
Thank you!
Let's see if someone can help me out with this powershell script I am trying to write..
I have a $variable containing hundreds of lines (below you can see an example how it looks like)
I need to save different lines in different variables following some pattern like this.
(white spaces) + MPS + lpgp*
(white spaces) + MPS + lpnz*
(white spaces) + MPS + lpgb* ...
I am trying to do something like
$variable | % { if ($_ -match "MPS LPGP*") {$lpgp += $_ }}
But it doesnt work
.....
MPS lpgpctx0001 MPS MPS_PLT_2005.0427 (v1.0) (lpgpctxli0002/27000 30705), start Tue 6/29 15:12 MPS lpnzctx0001 MPS MPS_PLT_2005.0427 (v1.0) (lpgpctxli0002/27000 30705), start Tue 6/29 15:12....
Users of MPS_ENT_CCU: (Total of 10 licenses issued; Total of 0 licenses in use)
Thank you!
- cruisader03
- Posts: 16
- Last visit: Tue Mar 15, 2011 2:44 am
trying to match lines and assign to variable
the first number in substring is the char to start from counting from 0the second number is how many chars to include$variable | % { New-Object PSObject -Property @{ ColumnA = $_.Substring(0,3) ColumnB = $_.Substring(4,11) ColumnC = $_.Substring(16,3) ... ... ... }}
trying to match lines and assign to variable
Hmm..I interpreted the problem differently. I thought the problem is one of parsing a text file and getting counts based on different matches.$a=0$b=0$c=0$d=get-content file.txt$d | foreach { Switch -rexeg ($_) { "MPS lpgp" {$a++ } "MPS lpnz" {$b++ } "MPS lpgb" {$c++ } default {"no match for $_"} }}write-host "lpgp count is $a"write-host "lpnz count is $b"write-host "lpgb count is $c"
trying to match lines and assign to variable
I think we are all wrong. Looks like a sort issue. Wish we had more info.
In any case teh fields solution will work for any and all problems but if it is a count issue then I suppose Jeff's solution is most elegant.
In any case teh fields solution will work for any and all problems but if it is a count issue then I suppose Jeff's solution is most elegant.
trying to match lines and assign to variable
Regardless of how you get there you end with with four variables that contain numbers. $a=20$b=33$c=50$d=45The best approach then to work with them is to create a custom object, which I believe was suggested earlier.new-object psobject -Property @{ ProductA=$a ProductB=$b ProductC=$c ProductD=$d}You can pipe this object to the Out-Chart cmdlet, which I'm assuming is the one from PowerGadgets.