Skip to content

Instantly share code, notes, and snippets.

@stknohg stknohg/ChangeConfig.ps1
Last active Aug 29, 2015

What would you like to do?
# 要Add-Type
Add-Type -AssemblyName System.Configuration
# アプリケーション構成ファイルを読み込む
$Map = New-Object System.Configuration.ExeConfigurationFileMap
$Map.ExeConfigFilename = ".¥Sample.config"
$Config = [System.Configuration.ConfigurationManager]::OpenMappedExeConfiguration($Map, [System.Configuration.ConfigurationUserLevel]::None)
# 設定値の取得、更新
$Setting = $Config.AppSettings.Settings["MY_KEY"]
If ($Setting -eq $null) {
$Config.AppSettings.Settings.Add("MY_KEY", "New Value");
} else {
$Setting.Value = "New Value";
# 保存
<?xml version="1.0" encoding="utf-8"?>
<!-- サンプルの設定 -->
<add key="MY_KEY" value="Current Value" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.