# Adjusting script to use preset variables

**URL:** <https://forums.powershell.org/t/adjusting-script-to-use-preset-variables/18038>\
**Category:** PowerShell Help\
**Created:** [November 25, 2021, 3:55pm UTC](https://forums.powershell.org/t/adjusting-script-to-use-preset-variables/18038 "2021-11-25T15:55:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Markyyys](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Markyyys](https://forums.powershell.org/u/Markyyys)\
**Post date:** [November 25, 2021, 3:55pm UTC](https://forums.powershell.org/t/adjusting-script-to-use-preset-variables/18038/1 "2021-11-25T15:55:52Z")

</div>

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](https://www.powershellgallery.com/packages/Posh-IC/0.0.5/Content/Search-Registry.ps1)

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?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 25, 2021, 4:00pm UTC](https://forums.powershell.org/t/adjusting-script-to-use-preset-variables/18038/2 "2021-11-25T16:00:14Z")

</div>

Mark,  
Welcome to the forum. 👋🏽

> [@Markyyys](#):
>
> What I really need though is to specifiy those variables in the script itself.

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.

---

<div class="post-metadata">

**Author:** ![Markyyys](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Markyyys](https://forums.powershell.org/u/Markyyys)\
**Post date:** [November 25, 2021, 4:17pm UTC](https://forums.powershell.org/t/adjusting-script-to-use-preset-variables/18038/3 "2021-11-25T16:17:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Markyyys](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Markyyys](https://forums.powershell.org/u/Markyyys)\
**Post date:** [November 25, 2021, 5:08pm UTC](https://forums.powershell.org/t/adjusting-script-to-use-preset-variables/18038/4 "2021-11-25T17:08:41Z")

</div>

Oh, think I got it.

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

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 25, 2021, 7:25pm UTC](https://forums.powershell.org/t/adjusting-script-to-use-preset-variables/18038/5 "2021-11-25T19:25:18Z")

</div>

> [@Markyyys](#):
>
> Oh, think I got it.

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. 👍🏽

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. 😉

---

<div class="post-metadata">

**Author:** ![Markyyys](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Markyyys](https://forums.powershell.org/u/Markyyys)\
**Post date:** [November 25, 2021, 8:24pm UTC](https://forums.powershell.org/t/adjusting-script-to-use-preset-variables/18038/6 "2021-11-25T20:24:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:20pm UTC](https://forums.powershell.org/t/adjusting-script-to-use-preset-variables/18038/7 "2024-05-16T20:20:13Z")

</div>

Closed on May 16, 2024, 8:20pm UTC


