Last active
November 14, 2017 03:23
-
-
Save techthoughts2/4f249d49476eec92c691 to your computer and use it in GitHub Desktop.
Tests to verify that the script is running as a domain user or local user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Verifies if currently logged in user is a local user or domain user | |
.DESCRIPTION | |
This function will evaluate the users domain and determine if the current user is a domain user or local user. If true is returned the user is a domain user, if false is returned the user is a local user. | |
.EXAMPLE | |
Test-DomainUser | |
This will return a true/false indicating if the user is a domain user or not | |
.EXAMPLE | |
Test-DomainUser -Verbose | |
This will return a true/false indicating if the user is a domain user or not. Verbose output will be shown. | |
.OUTPUTS | |
Boolean value | |
.NOTES | |
Author: Jake Morrison | |
http://techthoughts.info | |
#> | |
function Test-DomainUser { | |
[CmdletBinding()] | |
Param() | |
[bool]$domainUser = $true #assume they are | |
Write-Verbose -Message "Getting current domain of user..." | |
$dom = $env:USERDOMAIN.ToUpper() | |
Write-Verbose -Message "Domain: $dom" | |
Write-Verbose -Message "Getting hostname..." | |
$hostName = hostname | |
$hostName = $hostName.ToUpper() | |
Write-Verbose -Message "Hostname: $hostName" | |
Write-Verbose -Message "Evaluating if domain user or local user..." | |
if ($dom -eq $hostName) { | |
Write-Verbose "Context user: $dom\$env:USERNAME" | |
Write-Verbose "User is a local user" | |
$domainUser = $false | |
} | |
else { | |
Write-Verbose "Context user: $dom\$env:USERNAME" | |
Write-Verbose "User is a domain user" | |
} | |
return $domainUser | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment