我正在编写一个在 Windows 7 和 Windows 10 中使用的脚本,用于在 HKLM:\\Software\\Classes 中进行 Windows 注册表搜索。到目前为止,我的代码可以工作,但速度非常慢。大约需要 30 分钟才能完成。
\n我还需要使用Set-Location来避免 Get-ItemProperty 出现错误,这是因为 $path 不是有效对象。
\n我怎样才能加快这段代码的速度?怎么了?
\nregsearch.ps1(应用Mathias R. Jessen 的答案)Function Get-RegItems\n{\n Param(\n [Parameter(Mandatory=$true)]\n [string]$path,\n [string]$match)\n\n #Set Local Path and ignore wildcard (literalpath)\n Set-Location -literalpath $path\n $d = Get-Item -literalpath $path\n\n # If more than one value -> process\n If ($d.Valuecount -gt 0) {\n $d |\n # Get unkown property\n Select-Object -ExpandProperty Property |\n ForEach {\n $val …Run Code Online (Sandbox Code Playgroud) powershell performance foreach powershell-2.0 powershell-3.0