我有以下PowerShell代码,它给了我一个计数输出。我想连续或削减前11个字符,只留下“9”或那里的数字/更大。有没有人知道如何在PowerShell中缩短字符串或从返回值中删除X个字符数量?
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>
答案 0 :(得分:4)
如果您只想要Count
属性的值,那么您应该只是这样:
(Get-Content * -EA SilentlyContinue | Select-String "^\[Schedule\]" |
Measure-Object).Count
答案 1 :(得分:0)
不确定这是否是其他人会认为有用的东西,但我能够将其声明为变量,以“;”结束命令然后使用SubString(11)在第11个字符后切断所有内容。
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>