2013-07-30 36 views
1

我有以下PowerShell代碼,它給了我一個計數輸出。我想要連接或剪切前11個字符,只留下「9」或將存在/更大的數字。有沒有人有任何想法如何縮短字符串或從PowerShell中返回的值中刪除X個字符?Powershell中的Concat輸出

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

不知道這是什麼別人會碰到有用,但我可以把它宣佈爲varible,以結束該命令「;」然後使用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> 
4

如果你想Count財產只是價值,那麼你應該簡單地得到這一點:

(Get-Content * -EA SilentlyContinue | Select-String "^\[Schedule\]" | 
    Measure-Object).Count 
+0

這也適用於只是一個良好和很多對眼睛更舒適。謝謝! – RedHatcc