Skip to content

Instantly share code, notes, and snippets.

@dg1an3
Created August 18, 2022 22:05
Show Gist options
  • Save dg1an3/dc09203fb01930492c36e97103f534bf to your computer and use it in GitHub Desktop.
Save dg1an3/dc09203fb01930492c36e97103f534bf to your computer and use it in GitHub Desktop.
App config powershell helpers
param([String]$key)
Get-ChildItem .\*.config -Recurse |
Where-Object { ([xml](Get-Content $_)).SelectSingleNode("//add[@key='$key']") } |
ForEach-Object {
$xml = [xml](Get-Content $_)
$xml.SelectSingleNode("//add[@key='$key']").Value
}
param([String]$key, [String]$value)
Get-ChildItem .\*.config -Recurse |
Where-Object { ([xml](Get-Content $_)).SelectSingleNode("//add[@key='$key']") } |
ForEach-Object {
$xml = [xml](Get-Content $_)
$xml.SelectSingleNode("//add[@key='$key']").Value = $value
$xml.Save($_)
}
@dg1an3
Copy link
Author

dg1an3 commented Sep 27, 2022

$allConfig = gci -Recurse $Env:ProgramFiles\Hoodat\*.exe|%{[System.Configuration.ConfigurationManager]::OpenExeConfiguration($_.FullName)}

@dg1an3
Copy link
Author

dg1an3 commented Sep 27, 2022

$allConfig|%{$_.AppSettings.Settings[Environment]}

@dg1an3
Copy link
Author

dg1an3 commented Sep 27, 2022

$allConfig|%{$_.AppSettings.Settings.Remove('Environment')}

@dg1an3
Copy link
Author

dg1an3 commented Sep 27, 2022

$allConfig|%{$_.AppSettings.Settings.Add('Environment', 'Value')}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment