Powershell grab text position 148-182, each line.

Dear expert.

I need help with this code:
$time = ((Get-Date).Adddays(-100))
$pathlog =  "\\server\log_*"
$Pattern = "^01","^03"
$results = Get-ChildItem $pathlog -Recurse | where-object {$_.LastWriteTime -ge $time} |
	Select-String -Pattern $Pattern | 
	Group-Object Path |
	% { #Foreach-object alias
		$_.Group | Select-Object Line
}
if ($results) {
$results | Out-File D:\wei_test\resulttest.txt
$text = Get-Content -Path D:\wei_test\resulttest.txt
$text.Substring(148, 182)
$results = 1
} 

Open in new window


Now I would like to grab the Out-File result text line position  148 to 182 in each lines and show it in the powershell window.
I got a error:
 
Exception calling "Substring" with "2" argument(s): "startIndex cannot be larger than length of string.
Parameter name: startIndex"
At line:37 char:1
+ $text.Substring(148, 182)

Kinda stuck with this. thx for the help.
LVL 1
WeTiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
SubString expects int startIndex, int length, not int startIndex, int stopindex
You'll need SubString(148, 35)
Then if you want to export the lines to a file, you need to use -ExpandProperty in the Select-Object (and don't use aliases in scripts; use aliases only in interactive command lines).
$time = ((Get-Date).Adddays(-100))
$pathlog =  "\\server\log_*"
$Pattern = '^(01|03)'
$results = Get-ChildItem $pathlog -Recurse | Where-Object {$_.LastWriteTime -ge $time} |
	Select-String -Pattern $Pattern |
	Group-Object Path |
	Foreach-Object {
		$_.Group | Select-Object -ExpandProperty Line
	}
If ($results) {
	$results | Out-File D:\wei_test\resulttest.txt
	$text = Get-Content -Path D:\wei_test\resulttest.txt
	$text.Substring(148, 35)
	$results = 1
}

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WeTiAuthor Commented:
as great as always, and yes, i will not sue alias in coding. Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.