Adjusting script to use preset variables

Hi all. I could really use some help adjusting this script please? I found an amazing script to search the windows registy, by Bill Stewart PowerShell Gallery | Search-Registry.ps1 0.0.5

It takes variables from the command line, and it works just great, eg .\search-registry.ps1 -matchdata -startkey HKLM:\ -pattern “whatever”

So writing a batch script to run this with the variables is simple enough, even for me.

What I really need though is to specifiy those variables in the script itself. I’ve tried myself but whatever I do just seems to break it.

Can anyone help please?

Welcome to the forum. :wave:t4:

Why? Why change something perfectly working and making it worse or at least less flexible than before? You can call the script from within another script with the desired parameters.

Hi Olaf, thanks for coming back to me.

I considered just calling it from another script, which works great. Unfortunately, I’m looking to use it as an Intune app detection script, and this means I can’t specify variables to start with, nor can I call another script. It’s got to be all in one, like it isn’t hard enough in the first place.

I seriously marvel at people who can write these things in the first place! I’m not that good…

So, yeah, gotta be all in one

Oh, think I got it.

$reg = (Get-ItemProperty -Path HKLM:\SYSTEM\My_Path)
if ($reg -like '*Whatever*'){
    Write-Output True }
    else {
    write-output False

Great. I do not get how the snippet you posted relates to the question you asked and the script you refered to but anyway - I’m glad you found a solution. :+1:t4:

For the next time: The param block at the beginning of the script contains all parameters you can provide for the script at the command line. Instead of providing them at the command line you simply do the variable definitions there. That’s no rocket science. :wink:

Yeah, the script was way over complicated for what I needed, but it worked. Just needed something that checked the registry for a particular key.

I tried commenting out the param bit, and putting the vars in lower, but it just complained. Your idea is much simpler!

Thanks again for your help