用于查找注册表项的PowerShell脚本

时间:2015-11-10 15:26:57

标签: powershell

我需要一些帮助,我想创建一个powershell脚本,在注册表中只搜索密钥RebootRequired,不需要任何值或数据搜索。 使用IF find在文件夹C中创建一个名为RebootRequired.txt的txt文件:\ Candi \

甚至可能吗?

一直在试用一些脚本,但是如果它存在于注册表中,我可以让脚本找到密钥。

1 个答案:

答案 0 :(得分:1)

您可以使用Get-ChildItem -Recurse检索所有密钥,然后使用Where-Object过滤密钥名称。

Registry提供商与FileSystem提供商略有不同,因为每个项目的Name属性是整个关键路径(即。HKEY_LOCAL_MACHINE\Software\Microsoft而不是Microsoft只是PSChildName)。您可以使用if(@(Get-ChildItem HKLM: -Recurse |Where-Object {$_.PSChildName -eq 'RebootRequired'})) { # Something was returned! Create the file New-Item C:\Candi\RebootRequired.txt -ItemType File } 来引用叶名称:

-ErrorAction SilentlyContinue

您可以使用Get-ChildItem

public class Heap<T> { /* no need for items to extend Comparable anymore */ private final Comparator<T> cmp; public Heap(Comparator<T> cmp) { this.cmp = cmp; ... } ... } 参数参数来禁止来自无法访问的密钥的错误消息