我很好奇我已经制作了一个功能的进度条,但是我已经尝试过去一小时将它实现到我的代码中但没有运气......
甚至可能,我的程序是什么读取svr名称列表然后基本上调用一个函数从svr获取信息并写入文件所以我有原始数据日志,但是我厌倦了看一个空白屏幕,所以我想添加某种指标.. :(但没有运气..
非常感谢一些评论,谢谢大家:)
清除-主机
$serverList = Get-Content C:\RServerList.txt
$creds = Get-Credential
function Build_Directories
{
foreach ($s in $serverList)
{
New-Item -ItemType directory -Path C:\Data\$s
}
}
function xecute_eLogs
{
$i = 1
foreach ($s in $serverList)
{
Invoke-Command -ComputerName $s -ScriptBlock {Get-EventLog -LogName security -EntryType "Error","Warning"} -credential $creds | Out-File "C:\Data\$s\sysElogs.txt"
Write-Progress -Activity "Retrieving data from $s which is $i out of $($serverList.Count)" ` -percentComplete ($i++*100/$serverList.Count)
}
}
Build_Directories
xecute_eLogs
答案 0 :(得分:4)
您可以使用Write-Progress
这是一个例子:
$max = 25
for ($i = 1; $i -le $max; $i++)
{
Write-Progress -Activity "Counting $i until $max" `
-percentComplete ($i*100/$max)
sleep -Seconds 1
}
修改强> 考虑到对地位的评论。
适应您的脚本,它看起来像这样:
$i = 1
foreach ($s in $serverList)
{
Invoke-Command -ComputerName $s -ScriptBlock {Get-EventLog -LogName system -EntryType "Error","Warning"} -credential $creds | Out-File "C:\Data\$s\sysElogs.txt"
Write-Progress -Activity "Retrieving data from $s which is $i out of $($serverList.Count)" -percentComplete ($i++*100/$serverList.Count) -status Running
}