gpt4 book ai didi

powershell - 将带有星号的注册表项传递给测试路径

转载 作者:行者123 更新时间:2023-12-04 14:43:02 25 4
gpt4 key购买 nike

我想通过 Test-Path 运行此注册表路径在 PowerShell 中,但它包含一个星号,它在注册表中有效,但在 Windows 路径中无效。

问题是,当我通过它时,Test-Path将星号视为通配符,因此这需要非常非常长的时间,因为它会检查 Classes 的所有子路径无论如何都不像我想测试的那样。

有什么办法可以正确地传递那个星号吗?某种逃生机制?

Write-Host "Begin"
Test-Path "HKLM:\SOFTWARE\Classes\*\shell\Some shell extension"
Write-Host "End"

最佳答案

使用 -LiteralPath 防止参数 globbing/wildcard matching .

-LiteralPath<String[]>

Specifies a path to be tested. Unlike Path, the value of the LiteralPath parameter is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.


Write-Host "Begin"
Test-Path -LiteralPath "HKLM:\SOFTWARE\Classes\*\shell\Some shell extension"
Write-Host "End"

关于powershell - 将带有星号的注册表项传递给测试路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31506196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com