$PSDefaultParameterValues?

Hi all!

Does PSU have a way to set $PSDefaultParameterValues globally? I’m thinking it would be really handy to predefine values like -Server and -Credential for Get-ADUser so you never have to remember to include those parameters in your scripts.

I’ve tried setting it as a simple “Variable” with a value like this:

@{“ConvertTo-Csv:Delimiter”="|"}

… but any call to ConvertTo-Csv still uses the comma as a delimiter, so it seems like PSU is not honouring the variable.

Any ideas?

Hey… so I’m actually doing this because of an issue with a module I built.
My module interacts with the servicenow API and has a function called set-servicenowauth
It basically sets a credential and instance into script scope of the module and those are used by default in all of its functions as the -credential and -instance params, which has generally been fine outside of PSU.

I noticed a scoping issue when I tried using it in my dashboard.ps1, as those script variables get lost - the module is basically getting re-imported when my dashboard starts. So I would have to re-set my auth in my dashboard once it’s running…

Since standard variables do get pulled down into the dashboards automatically when they run, as a workaround for now I’m actually using $PSDefaultParameterValues in my dashboard.ps1 to apply the same variables to all my servicenow functions with a wildcard instead of using set-servicenowauth to set them in module script scope, and it works, i can now access that in my pages.

Looks like this:

$PSDefaultParameterValues = @{
    "*-ServiceNow*:instance"="$servicenowInstance.service-now.com"
    "*-ServiceNow*:credential"=$ServicenowCredential
}

The credential and instance are stored as PSU variables, and I’ve got this bit of code in my dashboard.ps1. It’s a hacky workaround for now until I add a switch to my module function set-servicenowauth -globalscope or something like that - or just fully change it into that scope by default.

But yeah I get what you mean, on being able to set them at a PSU level so that it passes down into all dashboards/scripts alike, I dont think there’s a way to currently do this, and I’m not sure if that would be feasible - maybe adam can advise.

Thanks @insomniacc! Defining the defaults at the top of the script is a good workaround for now.