0

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.

4
  • 5
    What exactly have you tried? Show us your code! Commented Nov 10, 2015 at 15:30
  • Will you need to run it against locally or remotely ? On a single or multiple computers ? What version of PowerShell can you use ? As soon as you post some sample code you will see answers popping ^_^ here people don't usually write blind code : ) Commented Nov 10, 2015 at 17:21
  • @sodawillow sometimes I can't help it :( Commented Nov 10, 2015 at 21:45
  • I think I had noticed this ^^ Can't help being helpful, huh ? :-) Commented Nov 11, 2015 at 19:08

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much! :) it works perfect :) would it be more effective if i specify the path a bit more? i know the Key "spawns" in HKLM\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\ //Best regards
i just now need to set the script to have permissions to search HKLM :) //Best Regards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.