Skip to content

Instantly share code, notes, and snippets.

@tuespetre
Last active August 9, 2018 14:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuespetre/c757bdb9b5b5ec1be225 to your computer and use it in GitHub Desktop.
Save tuespetre/c757bdb9b5b5ec1be225 to your computer and use it in GitHub Desktop.
A PowerShell cmdlet for setting environment variables for AppPoolIdentity users
function global:Set-AppPoolEnvVariable {
param (
[string]$appPool = $(Read-Host "Application Pool"),
[string]$varName = $(Read-Host "Variable name"),
[string]$varValue = $(Read-Host "Variable value")
)
$sec = "System.Security.Principal";
$acct = New-Object "$sec.NTAccount" -ArgumentList "IIS AppPool\$appPool";
$sid = $acct.Translate([System.Type]::GetType("$sec.SecurityIdentifier")).Value;
Set-ItemProperty -Path "Registry::HKEY_USERS\$sid\Environment" -Name $varName -Value $varValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment