Skip to content

Instantly share code, notes, and snippets.

@dpo007
Last active January 14, 2020 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpo007/0628db460cef127b3a513020f5e6502d to your computer and use it in GitHub Desktop.
Save dpo007/0628db460cef127b3a513020f5e6502d to your computer and use it in GitHub Desktop.
Powershell function :: Tests to see if Char value is "empty".
# Tests to see if Char value is "empty".
# Ran into a need to test for "empty" [Char] DriveLetters when using Get-Partition,
# and the usual PS comparison techniques weren't working with Char (ie: Char is never Null).
# If you (re)cast it to a Boolean, it'll return expected $True\$False to test for "Empty".
# This Gist exists as a reminder of that.
function CharIsEmpty {
param (
[Parameter(Mandatory=$True)]
[char]$CharToTest
)
# $True if "empty".
return (!([bool]$CharToTest))
}
# Usage:
# If (CharIsEmpty($MyChar)) { Write-Host 'Char is "empty".' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment