Sometimes, you’d like to check if a particular user (like a local admin) is logged in, before you run your script. Here is that code:

$CurrentlyLoggedInUserName = [Environment]::UserName

if( $CurrentlyLoggedInUserName -eq “jwolcott”) {

write-host “true”

}else {

write-host “false”

}