Reputation: 13
i need some help, i want to create a powershell script that searches the registry for just the key RebootRequired, no value or data search is needed. with a IF find create a txt file named RebootRequired.txt in folder C:\Candi\
is that even possible?
been trying out some scripting, but i can barley make the script to find the key if it present within the registry.
Upvotes: 0
Views: 11338
Reputation: 174435
You could retrieve all keys with Get-ChildItem -Recurse
and then filter on key names with Where-Object
.
The Registry
provider is a little different from the FileSystem
provider, in that the Name
property of each item is the entire key path (ie. HKEY_LOCAL_MACHINE\Software\Microsoft
instead of just Microsoft
). You can use PSChildName
to refer to the leaf name:
if(@(Get-ChildItem HKLM: -Recurse |Where-Object {$_.PSChildName -eq 'RebootRequired'}))
{
# Something was returned! Create the file
New-Item C:\Candi\RebootRequired.txt -ItemType File
}
You can suppress error messages from inaccessible keys with the -ErrorAction SilentlyContinue
parameter argument with Get-ChildItem
Upvotes: 1