< Back

Set-DefaultValue

Sat Jan 11, 2020 2:49 pm

NAME Set-DefaultValue



SYNOPSIS

This function sets a variable to a specified default value in the global scope if it is null.





SYNTAX

Set-DefaultValue [-defaultValue] <Object> [[-variable] <Object>] [<CommonParameters>]





DESCRIPTION





PARAMETERS

-defaultValue <Object>

The default value for the variable.



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-variable <Object>

The variable to be assigned a default value if it is null.



Required? false

Position? 2

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$var = $null



$var | Set-DefaultValue 42 # $var is now 42









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>$var = 5



$var | Set-DefaultValue 42 # $var is still 5











RELATED LINKS