powershell 提取数字


PowerShell交流中心分类: Powershell基础powershell 提取数字
1
小兵狗二蛋 asked 6 年 ago

PS C:\> vssadmin list shadows | Select-String “/” | measure -line

Lines Words Characters Property
—– —– ———- ——–
5

请问要怎样提取数字5,不能包含空格和空行。老大给的答案我执行没有结果。我的ps版本是2.0

PS C:\> (vssadmin list shadows | where { $_ -like ‘Contents of shadow copy set ID*’ }).count
PS C:\>

1 Answers
1
Best Answer
Mooser Lee 管理员 answered 6 年 ago

我明白了,我的系统语言是中文,你的系统可能是英文,所以vssadmin输出的内容字符串可能不一致。
你试试这句:

PS> $vsIds = vssadmin list shadows | where { $_ -match '^\b.*{' }
PS> $vsIds.Count
2

实在不行再把vssadmin list shadows的输出贴出来,我看下。

小兵狗二蛋 replied 6 年 ago

谢谢~,这次是可以执行