What would be the best way to filter out built-in variables?

I have a function that makes it easier to configure BIOS options, the way it works is that I have each option as an optional parameter like this:

#Sets the behavior of the system after AC power is lost [Parameter(Mandatory=$false)] [ValidateSet('off','on',"last")] [string]$ACpower, 

Then I get all of the variables that are a part of my function and have some data in them. This is where I want to improve it a bit, right now I’m filtering out the built-in variables by manually adding them in a long list to -exclude, and filtering out my empty ones with where-object -property value -notlike ”.

It works fine, but I want to know if there is a more future proof way, because if powershell 6 or whatever adds another built-in variable I will need to manually add that to the list. The ideas I’ve had was to use get-variable at the beginning before all of my variables are defined and filter out every variable that matches those variables but that doesn’t seem to work inside a function.

Another idea I’ve had was to add a very unique description to my variables and filter on variables that has that description, but I can’t figure out how to add descriptions to these variables.

And if it’s not clear why I want to get the variables with get-variable, it’s because I use the name and value to create the arguments used for the dell and HP bios configuration tools, and the WMI commands used to configure Lenovo machines.

submitted by /u/Thotaz
[link] [comments]

Leave a Reply