Powershell 从何处开始计算对象
我目前正在尝试编写一个小的powershell脚本(我没有编写powershell脚本的经验,所以我想把它作为一个测试),该脚本在我们的svn存储库中循环,计算有多少提交被“Review by;no one”注释,因为这表示未查看的提交 我目前有以下几点Powershell 从何处开始计算对象,powershell,Powershell,我目前正在尝试编写一个小的powershell脚本(我没有编写powershell脚本的经验,所以我想把它作为一个测试),该脚本在我们的svn存储库中循环,计算有多少提交被“Review by;no one”注释,因为这表示未查看的提交 我目前有以下几点 $repositorys = @("Path1", "path2","path3","path4") $matches = 0 foreach ($path in $repositorys){ "Path: {0}" -f $path.tost
$repositorys = @("Path1", "path2","path3","path4")
$matches = 0
foreach ($path in $repositorys){
"Path: {0}" -f $path.tostring()
( [xml] (svn log --xml $path)).log.logentry | Where-Object {$_.msg -imatch "(Reviewed By: (no(.*)one))" } | measure-object | format-list
}
这将根据找到的匹配项的数量为我提供计数输出
Count Average Sum Maximum Minimum Property
----- ------- --- ------- ------- --------
1
如果我删除了度量对象,那么我将获得SVN提交的详细信息(版本、作者、消息、日期等)
本质上,我希望能够报告的是未审核提交的数量和详细信息(因此,本质上是上述两种方法之间的合并)。所以我有一份报告看起来像
路径1:
Number of un-reviewed commits: xx
Revision Author
-------- -------
x x
有谁能给我点化一下吗??这可能吗?那么,在这种情况下,您必须输出两种不同的内容。我建议您将执行该操作的管道的结果保存在变量中,然后执行以下操作:
$x = ( [xml] (svn log --xml $path)).log.logentry | Where-Object {$_.msg -imatch "(Reviewed By: (no(.*)one))" }
Write-Host Number of un-reviewed commits: ($x.Count)
$x | fl
因此,您只需输出数字,然后从管道中删除集合以打印它。这就是cmdlet的用途
[xml] (svn log --xml $path)).log.logentry |
? {$_.msg -imatch "(Reviewed By: (no(.*)one))" } |
tee -variable temp |
measure |
% { "Number of un-reviewed commits: $($_.count)" }
$temp | fl
这里没有什么不能通过手动分解管道和分配变量来完成的,但是“tee”是一个方便的快捷方式
它的另一个常见用途是将中间结果写入文件。有关详细信息,请参阅“帮助-示例”