Skip to content

Instantly share code, notes, and snippets.

@axdiamond
Created April 12, 2018 18:27
Show Gist options
  • Save axdiamond/e0250ca5837c03518a17aa925f45f21e to your computer and use it in GitHub Desktop.
Save axdiamond/e0250ca5837c03518a17aa925f45f21e to your computer and use it in GitHub Desktop.
Powershell to set ASP Core Environment Variables
#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