显示' reg copy'的进度条命令

时间:2017-12-29 15:43:31

标签: powershell

我想知道我有谁知道如何为多个REG Copy项添加进度条?

Explorer UI可与Copy-Item一起正常使用,但不适用于reg copy

我复制的reg文件非常粗糙,需要一段时间才能复制,所以我认为某种进度条会有所帮助。这是我的脚本示例,我尝试为其获取进度条:

$TestPath = "Registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers"
    if ( Test-Path -path $TestPath  )  {          
    reg copy "\\$SourceHost\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers" "\\$DestHost\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers" /s /f | out-null
    }
    Else {
    reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers" /f | out-null
    reg copy "\\$SourceHost\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers" "\\$DestHost\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers" /s /f  | out-null
    }


    $TestPath = "Registry::HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers"
    if ( Test-Path -path $TestPath  )  {  
    reg copy "\\$SourceHost\HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers" "\\$DestHost\HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers" /s /f | out-null
    }
    Else {
    reg add "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers" /f | out-null
    reg copy "\\$SourceHost\HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers" "\\$DestHost\HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers" /s /f | out-null
    }
...

5 个答案:

答案 0 :(得分:1)

我们知道循环可能效率低下,但有时会有必要的东西。 怎么样的。

$TargetRegKeys = 'Registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers',
'Registry::HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers'  

$TargetRegKeys | ForEach-Object -Begin {Clear-Host; $I = 0; $out = ""} -process { 
{
    # if ( Test-Path -path $_ ) { reg copy "\\$SourceHost\$_"  "\\$DestHost\$_" / s /f | out-null }
    # Else { reg copy "\\$SourceHost\$_"  "\\$DestHost\$_" / s /f | out-null }
}

$I = $I + 1
Start-Sleep -Seconds 3

Write-Progress -Activity "$($TargetRegKeys.Count) registry keys to process" -Status "Progress:" -PercentComplete ($I / $TargetRegKeys.Count * 100)
Start-Sleep -Seconds 3
} -end {$out}

当然,Sleeps仅用于测试,因此可以看到进度条。 '如果'被注释以避免对我的环境进行任何更改。

答案 1 :(得分:0)

正如James C.已经提到的那样,reg不支持进度指示器。但是,Powershell可以使用Write-Progress。像这样,

write-progress -activity "Updating registry" -status "Working: " -percentComplete 20
reg copy ...
write-progress -activity "Updating registry" -status "Working: " -percentComplete 40
reg copy ...
write-progress -activity "Updating registry" -status "Working: " -percentComplete 60
reg copy ...
write-progress -activity "Updating registry" -status "Working: " -percentComplete 80
reg copy ...

在这种特殊情况下,您必须以手动方式决定步骤和增量。完成步骤取决于您,所以可能是这样的:

$TestPath = "Registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers"
write-progress -activity "Updating registry" -status "Working: " -percentComplete 20
if ( Test-Path -path $TestPath  )  {          
    reg copy ...
}
Else {
    reg add ...
    write-progress -activity "Updating registry" -status "Working: " -percentComplete 25
    reg copy ...
}

write-progress -activity "Updating registry" -status "Working: " -percentComplete 40
$TestPath = "Registry::HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers"
if ( Test-Path -path $TestPath  )  {  
    reg copy ...
}
Else {
    reg add ...
    write-progress -activity "Updating registry" -status "Working: " -percentComplete 50
    reg copy ...
}

答案 2 :(得分:0)

如果您愿意稍微参数化一下数据,可以使用类似于以下代码段的内容。 CopyInfos包含您的所有参数。据推测,您的输入都遵循类似的模式名称。第一行是每个复制操作的属性名称。其余行是每个副本的管道(|)分隔操作。使用上述建议,您可以根据参数计算完成百分比。在这里,您只需插入正确的参数,并为copyadd函数构建正确的字符串。

$CopyInfos = ("Path1|Path2|Path3", `
    "Print\Providers|Source1|Destination", `
    "BowWowWow\Print\Providers|Source2|Destination2", `
    "Meow\Print\Providers|Source13|Destination3", `
    "Ow!\Print\Providers|Source14|Destination44", `
    "Wow6432Node\Print\Providers|Source15|Destination555" 
     ) | ConvertFrom-CSV -Delimiter "|"

$x = 0
foreach ($CopyInfo in $CopyInfos) {
  $percent = [int] (($x * 100) / $CopyInfos.Count)
  write-progress -Activity "$($CopyInfo.Path1)" -Status "Starting" -PercentComplete $Percent
  Start-Sleep -Seconds 2

  $x++
  $percent = [int] (($x * 100) / $CopyInfos.Count)
  write-progress -Activity "$($CopyInfo.Path1)" -Status "Finished" -PercentComplete $Percent
  Start-Sleep -Milliseconds 250
}

答案 3 :(得分:0)

如果您在运行命令的计算机上安装了Powershell 5.0,则可以执行以下操作。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<ul class="menu">
  <li class="holdingbox">
    <!-- start message -->
    <!--                    <a href="#">/shipments/i/{'url_string']-->
    <div class="leftbox" style="width: 100%; left: 0px; overflow: hidden;">
      <a href="http://192.168.1.178:8000/notifications/4d798673-fe2e-4294-81dd-49969df0dff6">
        <div class="pull-left">
          <!-- User Image -->
          <img src="/images/clipboard.png" class="img-circle" alt="Shipment">
        </div>
        <!-- Message title and timestamp -->
        <h4>
          Shipment Created
          <small><i class="fa fa-clock-o"></i> 2 hours ago</small>
        </h4>
        <!-- The message -->
        <p>Pro Number - 214439</p>
      </a>
    </div>
    <div class="rightbox" style="width: 0px; overflow: hidden;">
      <div class="content1">Mark Read<br><img src="https://upload.wikimedia.org/wikipedia/commons/2/28/White_X_in_red_background.svg" width="10px" height="10px">
      </div>
    </div>
  </li>
  <li class="holdingbox">
    <!-- start message -->
    <!--                    <a href="#">/shipments/i/{'url_string']-->
    <div class="leftbox" style="width: 100%; left: 0px; overflow: hidden;">
      <a href="http://192.168.1.178:8000/notifications/c7e7add5-eaa2-4b3c-84fe-062322567d5f">
        <div class="pull-left">
          <!-- User Image -->
          <img src="/images/clipboard.png" class="img-circle" alt="Shipment">
        </div>
        <!-- Message title and timestamp -->
        <h4>
          Shipment Created
          <small><i class="fa fa-clock-o"></i> 2 weeks ago</small>
        </h4>
        <!-- The message -->
        <p>Pro Number - 2102000003</p>
      </a>
    </div>
    <div class="rightbox" style="width: 0px; overflow: hidden;">
      <div class="content1">Mark Read<br><img src="https://upload.wikimedia.org/wikipedia/commons/2/28/White_X_in_red_background.svg" width="10px" height="10px">
      </div>
    </div>
  </li>
  <li class="holdingbox">
    <!-- start message -->
    <!--                    <a href="#">/shipments/i/{'url_string']-->
    <div class="leftbox" style="overflow: hidden; width: 100%; left: 0px;">
      <a href="http://192.168.1.178:8000/notifications/1c578226-f735-4d62-be19-7deab4c08dbe">
        <div class="pull-left">
          <!-- User Image -->
          <img src="/images/clipboard.png" class="img-circle" alt="Shipment">
        </div>
        <!-- Message title and timestamp -->
        <h4>
          Shipment Created
          <small><i class="fa fa-clock-o"></i> 2 weeks ago</small>
        </h4>
        <!-- The message -->
        <p>Pro Number - 2102000002</p>
      </a>
    </div>
    <div class="rightbox" style="width: 0px; overflow: hidden;">
      <div class="content1">Mark Read<br><img src="https://upload.wikimedia.org/wikipedia/commons/2/28/White_X_in_red_background.svg" width="10px" height="10px">
      </div>
    </div>
  </li>
  <li class="holdingbox">
    <!-- start message -->
    <!--                    <a href="#">/shipments/i/{'url_string']-->
    <div class="leftbox" style="overflow: hidden; width: 100%; left: 0px;">
      <a href="http://192.168.1.178:8000/notifications/c975030e-64e9-4481-8fd0-0004242515d8">
        <div class="pull-left">
          <!-- User Image -->
          <img src="/images/clipboard.png" class="img-circle" alt="Shipment">
        </div>
        <!-- Message title and timestamp -->
        <h4>
          Shipment Created
          <small><i class="fa fa-clock-o"></i> 2 weeks ago</small>
        </h4>
        <!-- The message -->
        <p>Pro Number - 2102000001</p>
      </a>
    </div>
    <div class="rightbox" style="width: 0px;">
      <div class="content1">Mark Read<br><img src="https://upload.wikimedia.org/wikipedia/commons/2/28/White_X_in_red_background.svg" width="10px" height="10px">
      </div>
    </div>
  </li>
  <li class="holdingbox">
    <!-- start message -->
    <!--                    <a href="#">/shipments/i/{'url_string']-->
    <div class="leftbox" style="overflow: hidden; width: 100%; left: 0px;">
      <a href="http://192.168.1.178:8000/notifications/6721dd8c-4f45-422f-81d0-80fa4fe128f9">
        <div class="pull-left">
          <!-- User Image -->
          <img src="/images/clipboard.png" class="img-circle" alt="Shipment">
        </div>
        <!-- Message title and timestamp -->
        <h4>
          Shipment Created
          <small><i class="fa fa-clock-o"></i> 3 weeks ago</small>
        </h4>
        <!-- The message -->
        <p>Pro Number - 212222</p>
      </a>
    </div>
    <div class="rightbox" style="width: 0px;">
      <div class="content1">Mark Read<br><img src="https://upload.wikimedia.org/wikipedia/commons/2/28/White_X_in_red_background.svg" width="10px" height="10px">
      </div>
    </div>
  </li>
  <li class="holdingbox">
    <!-- start message -->
    <!--                    <a href="#">/shipments/i/{'url_string']-->
    <div class="leftbox">
      <a href="http://192.168.1.178:8000/notifications/48780be4-52af-4278-b67a-6544eda95aae">
        <div class="pull-left">
          <!-- User Image -->
          <img src="/images/clipboard.png" class="img-circle" alt="Shipment">
        </div>
        <!-- Message title and timestamp -->
        <h4>
          Shipment Created
          <small><i class="fa fa-clock-o"></i> 4 weeks ago</small>
        </h4>
        <!-- The message -->
        <p>Pro Number - 2010</p>
      </a>
    </div>
    <div class="rightbox">
      <div class="content1">Mark Read<br><img src="https://upload.wikimedia.org/wikipedia/commons/2/28/White_X_in_red_background.svg" width="10px" height="10px">
      </div>
    </div>
  </li>
  <li class="holdingbox">
    <!-- start message -->
    <!--                    <a href="#">/shipments/i/{'url_string']-->
    <div class="leftbox">
      <a href="http://192.168.1.178:8000/notifications/ca2583eb-5146-471d-b285-5178c35ab0a1">
        <div class="pull-left">
          <!-- User Image -->
          <img src="/images/clipboard.png" class="img-circle" alt="Shipment">
        </div>
        <!-- Message title and timestamp -->
        <h4>
          Shipment Created
          <small><i class="fa fa-clock-o"></i> 4 weeks ago</small>
        </h4>
        <!-- The message -->
        <p>Pro Number - 210200000</p>
      </a>
    </div>
    <div class="rightbox">
      <div class="content1">Mark Read<br><img src="https://upload.wikimedia.org/wikipedia/commons/2/28/White_X_in_red_background.svg" width="10px" height="10px">
      </div>
    </div>
  </li>
  <li class="holdingbox">
    <!-- start message -->
    <!--                    <a href="#">/shipments/i/{'url_string']-->
    <div class="leftbox">
      <a href="http://192.168.1.178:8000/notifications/1e23de34-d699-4e3a-9110-e02ab5ce000b">
        <div class="pull-left">
          <!-- User Image -->
          <img src="/images/clipboard.png" class="img-circle" alt="Shipment">
        </div>
        <!-- Message title and timestamp -->
        <h4>
          Shipment Created
          <small><i class="fa fa-clock-o"></i> 4 weeks ago</small>
        </h4>
        <!-- The message -->
        <p>Pro Number - 250006</p>
      </a>
    </div>
    <div class="rightbox">
      <div class="content1">Mark Read<br><img src="https://upload.wikimedia.org/wikipedia/commons/2/28/White_X_in_red_background.svg" width="10px" height="10px">
      </div>
    </div>
  </li>
  <li class="holdingbox">
    <!-- start message -->
    <!--                    <a href="#">/shipments/i/{'url_string']-->
    <div class="leftbox">
      <a href="http://192.168.1.178:8000/notifications/da74371c-2aa2-45ef-9b5d-28210c3816bb">
        <div class="pull-left">
          <!-- User Image -->
          <img src="/images/clipboard.png" class="img-circle" alt="Shipment">
        </div>
        <!-- Message title and timestamp -->
        <h4>
          Shipment Created
          <small><i class="fa fa-clock-o"></i> 1 month ago</small>
        </h4>
        <!-- The message -->
        <p>Pro Number - 214050</p>
      </a>
    </div>
    <div class="rightbox">
      <div class="content1">Mark Read<br><img src="https://upload.wikimedia.org/wikipedia/commons/2/28/White_X_in_red_background.svg" width="10px" height="10px">
      </div>
    </div>
  </li>
  <!-- end notification -->
</ul>

假设您的源计算机和目标计算机保持不变,您可以重复使用相同的会话变量,直到您完成。

答案 4 :(得分:0)

知道我不知道在这种情况下是否可以使用。

在最初的帖子中,我有2个注册复印作业,

他们可以被包裹在像

这样的东西之下吗?

$ AJob = { Reg copy1 ... reg copy2 ... reg copy3 ... ... }

然后这个$ AJob是运行思想GUI进度条?