PS script to add config
See original GitHub issueHi,
based on Jason Haley’s scripts I did create a PS script to easily add new web app’s to the config:
.\AddWebAppToLetsEncrypt.ps1 -webAppTarget "AppName" -webAppHosts "appname.com"
Here the script, if someone else wants to use it:
param(
[string]$webAppTarget,
[string]$webAppHosts,
[string]$renewXNumberOfDaysBeforeExpiration = "-1", # set this to e.g. 65 after first request to avoid hitting the cert-limit if the job is triggerd manually more than 5 times
[string]$tenantId = "<default tenant Id>",
[string]$subscriptionId = "<default subscription Id>",
[string]$webAppLetsEncrypt = "<default letsencrypt web app>",
[string]$resourceGroupLetsEncrypt = "<default resource group of letsencrypt web app>",
[string]$clientId = "<default client Id>",
[string]$clientSecret = "<default client secret>",
[string]$resourceGroupTarget = "<default target resource group>",
[string]$email = "<default email>")
Login-AzureRmAccount
Set-AzureRmContext -SubscriptionId $subscriptionId
# Load Existing Web App settings for source and target
$webAppSource = Get-AzureRmWebAppSlot -ResourceGroupName $resourceGroupLetsEncrypt -Name $webAppLetsEncrypt -Slot "production"
# Get reference to the source app settings
$appSettingsSource = $webAppSource.SiteConfig.AppSettings
# Create Hash variable for App Settings
$appSettingsTarget = @{}
# Copy over all Existing App Settings to the Hash
ForEach ($appSettingSource in $appSettingsSource) {
$appSettingsTarget[$appSettingSource.Name] = $appSettingSource.Value
}
# Add new settings
$appSettingsTarget["letsencrypt:" + $webAppTarget + "-clientId"] = $clientId
$appSettingsTarget["letsencrypt:" + $webAppTarget + "-email"] = $email
$appSettingsTarget["letsencrypt:" + $webAppTarget + "-hosts"] = $webAppHosts
$appSettingsTarget["letsencrypt:" + $webAppTarget + "-renewXNumberOfDaysBeforeExpiration"] = $renewXNumberOfDaysBeforeExpiration
$appSettingsTarget["letsencrypt:" + $webAppTarget + "-resourceGroup"] = $resourceGroupTarget
$appSettingsTarget["letsencrypt:" + $webAppTarget + "-subscriptionId"] = $subscriptionId
$appSettingsTarget["letsencrypt:" + $webAppTarget + "-tenantId"] = $tenantId
if ($appSettingsTarget.ContainsKey("letsencrypt:webApps")) {
if (!$appSettingsTarget["letsencrypt:webApps"].ToLower().Contains($webAppTarget.ToLower())) {
$appSettingsTarget["letsencrypt:webApps"] = $appSettingsTarget["letsencrypt:webApps"] + ";" + $webAppTarget
}
}
else {
$appSettingsTarget["letsencrypt:webApps"] = $webAppTarget
}
# Save Settings to Target
Set-AzureRmWebAppSlot -ResourceGroupName $resourceGroupTarget -Name $webAppLetsEncrypt -Slot "production" -AppSettings $appSettingsTarget
# Get reference to the source Connection Strings
$connectionStringsSource = $webAppSource.SiteConfig.ConnectionStrings
# Create Hash variable for Connection Strings
$connectionStringsTarget = @{}
# Copy over all Existing Connection Strings to the Hash
ForEach($connStringSource in $connectionStringsSource) {
$connectionStringsTarget[$connStringSource.Name] = @{ Type = $connStringSource.Type.ToString(); Value = $connStringSource.ConnectionString }
}
# Add new Connection String
$connectionStringsTarget["letsencrypt:" + $webAppTarget + "-clientSecret"] = @{ Type = "Custom"; Value = $clientSecret }
# Save Connection Strings to Target
Set-AzureRmWebAppSlot -ResourceGroupName $resourceGroupTarget -Name $webAppLetsEncrypt -Slot "production" -ConnectionStrings $connectionStringsTarget
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:9 (9 by maintainers)
Top Results From Across the Web
How can I introduce a config file to Powershell scripts?
Create a Powershell configuration file ( E.g. Config.ps1 ), then put all configuration as global variable and init it as a first step...
Read more >Creating a Config File for your PowerShell Scripts - Kyle Parrish
The first line begins the loop with Foreach ($i in $(Get-Content script.conf)){ which pulls in the content of the config file and sets...
Read more >How to use a config file (ini, conf,...) with a PowerShell Script?
If you config file don't have [Sections] or ; semicolon comments , you can do just $config = Get-Content $ConfigPath | ConvertFrom-StringData ....
Read more >about PowerShell Config
The powershell.config.json file contains configuration settings for PowerShell. PowerShell loads this configuration at startup.
Read more >Write, Compile, and Apply a Configuration - PowerShell
This exercise walks through creating and applying a Desired State Configuration (DSC) configuration from start to finish.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I took the liberty of making some improvements to the script, let me know what you think. I changed the way parameters work as I want to keep it generic, users can always create their own one-liner local script that calls it with the parameters they desire…
Hi,
I will improve the script a little as suggested and then create a PR, but I may need a few days until I have time for it…
regards Christoph