TRIMSTART COMMAND

Hi Team

I have the follwing STRING VARIABLE:

PS C:\WINDOWS\system32> $test

C:\Users\spate\Documents\SampleFile.txt:1:Server one
C:\Users\spate\Documents\SampleFile10.txt:1:Server one
C:\Users\spate\Documents\SampleFile3.txt:1:Server one
C:\Users\spate\Documents\SampleFile4.txt:1:Server one

 

I’m using the TrimStart() get the following output:

SampleFile.txt:1:Server one SampleFile10.txt:1:Server one
SampleFile3.txt:1:Server one
SampleFile4.txt:1:Server one

PS C:\WINDOWS\system32> $test.TrimStart(“C:\Users\spate\Documents”)

I’m getting following error:

Get-Process : A positional parameter cannot be found that accepts argument ’
C:\Users\spate\Documents\SampleFile.txt:1:Server one
C:\Users\spate\Documents\SampleFile10.txt:1:Server one
C:\Users\spate\Documents\SampleFile3.txt:1:Server one
C:\Users\spate\Documents\SampleFile4.txt:1:Server one
'.
At line:2 char:1

  • PS C:\WINDOWS\system32> $test.TrimStart(“C:\Users\spate\Documents”)
  • CategoryInfo : InvalidArgument: (:slight_smile: [Get-Process], ParameterBindingException
  • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetProcessCommand

 

CAN SOMEONE PLEASE HELP ME TO SHOW WHAT I’M DOINGWRONG.

THANKS

SUNNY

Some information is missing. The error shows Get-Process - where is this supposed to be used in the example?

It appears that $test is a result of a Select-String command. The default output MatchInfo object shows the Path, LineNumber, and Line properties. You can instead select the Filename property in place of Path:

$test | Foreach-Object {
    "{0}:{1}:{2}" -f $_.FileName,$_.LineNumber,$_.Line
}