Skip to content

Instantly share code, notes, and snippets.

@RichieBzzzt
Created May 22, 2017 21:51
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 RichieBzzzt/4061686751e1d272c70cacd96ed93200 to your computer and use it in GitHub Desktop.
Save RichieBzzzt/4061686751e1d272c70cacd96ed93200 to your computer and use it in GitHub Desktop.
$my_variable = "this is the value of my_variable"
if (Test-Path variable:my_variable) {
Write-Host $my_variable -ForegroundColor Magenta -BackgroundColor Yellow
}
else {
Write-Host 'Variable $my_variable does not exist.' -ForegroundColor Yellow -BackgroundColor Magenta
}
#note: my_non_existent_variable doesn't exist, so will go to else statement
if (Test-Path variable:my_non_existent_variable) {
Write-Host $my_non_existent_variable -ForegroundColor Magenta -BackgroundColor Yellow
}
else {
Write-Host 'Variable $my_non_existent_variable does not exist.' -ForegroundColor Yellow -BackgroundColor Magenta
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment