Last active
August 9, 2018 14:32
-
-
Save tuespetre/c757bdb9b5b5ec1be225 to your computer and use it in GitHub Desktop.
A PowerShell cmdlet for setting environment variables for AppPoolIdentity users
This file contains 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
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