In a previous post I forgot to include the PowerShell code for Get-FullDomainAccount. Sorry about that.
Here it is:
$env:USERDOMAIN = "<your domain>"
<#
.SYNOPSIS
Ensures that the given domain account also has the domain prefix. For example,
if the -DomainAccount is "IUSR_AbcXyz" the "<your domain>\IUSR_AbcXyz" would most likely
be returned. The domain is pulled from the current users domain, $env:USERDOMAIN.
If -Environment is provided, this will also run the -DomainAccount through
Get-EnvironmentDomainAccount to replace any environment specific information.
.LINK
Get-EnvironmentDomainAccount
Used to apply environment specific value to the domain account
.EXAMPLE
$result = Get-FullDomainAccount -DomainAccount "IUSR_AbcXyz"
$result -eq "<your domain>\IUSR_AbcXyz"
#>
Function Get-FullDomainAccount {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)]
[string] $DomainAccount,
[string ]$Environment = ""
)
$accountName = $DomainAccount;
if($Environment -ne "") {
$accountName = Get-EnvironmentDomainAccount -Environment $Environment -DomainAccount $DomainAccount;
}
if($accountName -match "ApplicationPoolIdentity") {
$accountName = "IIS AppPool\$accountName"
}
if($accountName -match "LocalSystem") {
$accountName = "$($env:COMPUTERNAME)\$accountName"
}
if($accountName -notmatch "\\") {
$accountName = $env:USERDOMAIN + "\" + $accountName;
}
return $accountName;
}