While you are writing PowerShell modules, with lot with parameters and you might want to verify these parameters are not ‘null’ to validate some business cases. In normal powershell inline scripting context, $variablename -eq “$null” would work :
if ($varibalename -eq $null) { Write-Host "variable is null.Please supply the values for variablename." }
RECOMMENDED APPROACH:
Efficient way of checking this inside a module is to use:
if (!$variablename) { Write-Host "variable is null.Please supply the values for variablename." }
If you would want to verify $variablename has any value except $null:
if ($variablename) { Write-Host "variablename is not null. do something here." }
Discover more from Cloud Distilled ~ Nithin Mohan
Subscribe to get the latest posts sent to your email.