I am having a hard time getting PowerShell to split a string after I "grep" it. I really want to get the 10 largest values out of an hourly web log.
The "Grep" works, but I am not then able to split it:
PS D:\Work\ps> D:\Work\ps\test\grep.ps1 Method invocation failed because [Microsoft.PowerShell.Commands.MatchInfo] doesn't contain a method named 'split'. At D:\Work\ps\test\grep.ps1:8 char:2 + $string.split($separator,0, $option) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
https://communary.net/2014/11/10/grep-the-powershell-way/ https://blogs.technet.microsoft.com/heyscriptingguy/2014/07/17/using-the-split-method-in-powershell/
##"[com.vendorStuff.utils.Stopwatch]"
$string = select-string "execution \:" "D:\logs\server.log" -ca
$separator = "execution \:"
$option = [System.StringSplitOptions]::RemoveEmptyEntries
$string.split($separator,1, $option)
#$data.Split("execution \:")[1]
It is imporatnt to note: I have already escaped: 'execution :' Couple of things that I have tried:
[string]$Data = sls 'execution \:' "D:\Work\ps\test\server.log" -ca
$data.split('execution \:')[1]
as well as:
$Data = (sls 'execution \:' "D:\Work\ps\test\server.log" -ca).tostring().split('execution \:')[1]
Thanks!