PowerShell check empty string

Last updated:

POWERSHELL

# Use the IsNullOrEmpty/IsNullOrWhiteSpace string method
[string]::IsNullOrEmpty(...)
[string]::IsNullOrWhiteSpace(...)

## Example to check string
if ([string]::IsNullOrWhiteSpace($User))

Remove leading and trailing space


# Use the .Trim() method

references:

.net - How can I check if a string is null or empty in PowerShell? - Stack Overflow PowerTip: Remove Leading and Trailing Spaces with PowerShell - Scripting Blog (microsoft.com)