Created
April 12, 2018 18:27
-
-
Save axdiamond/e0250ca5837c03518a17aa925f45f21e to your computer and use it in GitHub Desktop.
Powershell to set ASP Core Environment Variables
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
#Requires -RunAsAdministrator | |
$SiteName = "TEST" | |
$EnvVars = @( | |
@{Name="ENVIROMENT"; Value="Prod"}, | |
@{Name="LoggingMode"; Value="Verbose"} | |
); | |
function Set-AspNetCoreEnviromentVars { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$true, | |
ValueFromPipelineByPropertyName=$true, | |
Position=0)] | |
[string] | |
$SiteName, | |
[Parameter(Mandatory=$true, | |
ValueFromPipelineByPropertyName=$true, | |
Position=1)] | |
[System.Object[]] | |
$Vars | |
) | |
process { | |
$SitePath = "IIS:\\Sites\\$SiteName" | |
if (-Not (Get-Item $SitePath)) | |
{ | |
Write-Error "Site $SitePath not found" | |
return | |
} | |
Set-WebConfigurationProperty ` | |
-Filter '//aspNetCore/environmentVariables' ` | |
-PSPath $SitePath ` | |
-Name "Collection" ` | |
-Value $EnvVars | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment