1

I have the following PowerShell code which gives me a count output. I want to concat or cut the first 11 characters off leaving only "9" or the number that would be there / greater. Does anyone have any idea how to shorten a string or cut X amount of characters off of a returned value in PowerShell?

PS C:\Documents and Settings\All Users\Application Data\McAfee\Common Framework\Task> Get-Content * -erroraction silentlycontinue | findstr /R "^\[Schedule]" | Measure-Object | find "Count "
Count    : 9
PS C:\Documents and Settings\All Users\Application Data\McAfee\Common Framework\Task>

2 Answers 2

4

If you want just the value of the Count property, then you should simply get just that:

(Get-Content * -EA SilentlyContinue | Select-String "^\[Schedule\]" |
    Measure-Object).Count
Sign up to request clarification or add additional context in comments.

1 Comment

This also works just a well and is much more pleasant on the eyes. Thank you!
0

Not sure if this is what others will come across as useful, but I was able to declare it into a varible, end the command with a ";" then use SubString(11) which cuts everything off after the 11th character.

PS C:\Documents and Settings\All Users\Application Data\McAfee\Common Framework\Task> $string = Get-Content * -erroraction silentlycontinue | findstr /R "^\[Schedule]" | Measure-Object | find "Count "; $string.SubString(11)
9
PS C:\Documents and Settings\All Users\Application Data\McAfee\Common Framework\Task>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.