Today I found a little something in PowerShell. I needed a way to check if a variable/property was empty or not…
Now, who has written a small function to check this? 😉
I myself has written a function that provides a true/false output named ‘Validate-HasData’.
Did you know that you can do this with only 6 extra characters instead of writing a whole function and calling that over and over again?
Let’s get a process:
1 |
$var = Get-Process -Name WinLogon |
Now, how to check if the property ” has a value?
1 |
[bool]$var.sessionid |
This will give you a simple true/false output 🙂
Easy, short… I love it!