Powershell - If/else for checking if a user is logged in
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”
}