Skip to content

Instantly share code, notes, and snippets.

@rfennell
Created February 13, 2018 09:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfennell/01de24bd01fe44a5b6d67be2f719a876 to your computer and use it in GitHub Desktop.
Save rfennell/01de24bd01fe44a5b6d67be2f719a876 to your computer and use it in GitHub Desktop.
PowerShell script to update an app.config file based on a parameters.xml
function Update-AppConfig
{
[cmdletbinding()]
param
(
[parameter(Mandatory = $true, HelpMessage = "Name of app.exe.config file")]
[string]$AppConfigFile,
[parameter(Mandatory = $false, HelpMessage = "Name of parameters.xml file")]
[string]$ParametersFile = "parameters.xml"
)
if (-not (test-path $AppConfigFile)) {
Write-Error -Message "The application configuration $AppConfigFile was not found"
Return $null
}
if (-not (test-path $ParametersFile)) {
Write-Error -Message "The application configuration $ParametersFile was not found"
Return $null
}
[xml]$ParametersXml = Get-Content -Path $ParametersFile -Raw
[xml]$AppConfigXml = Get-Content -Path $AppConfigFile -Raw
Write-Verbose -Message "Using xpath to update values in '$AppConfigFile."
Foreach ($Node in $ParametersXml.Parameters.parameter) {
Write-Verbose -Message " Updating '$($Node.ParameterEntry.Match)' with value '$($Node.DefaultValue)'."
if ($Node.ParameterEntry.Match.endswith("/text()"))
{
$AppConfigXml.SelectSingleNode($Node.ParameterEntry.Match).InnerText = $Node.DefaultValue
} else
{
$AppConfigXml.SelectSingleNode($Node.ParameterEntry.Match).'#text' = $Node.DefaultValue
}
}
Write-Verbose -Message "Saving updated configuration."
$AppConfigXml.Save((Resolve-Path $AppConfigFile))
}
Update-AppConfig -AppConfigFile MyApp.exe.config -Verbose
@donomar19
Copy link

hi can you help me how to build script that i can deploy on intune that update onedrive version or downgrade the version. thank you

@rfennell
Copy link
Author

The above logic shows how to update a field in an XML file. My Azure DevOps Pipelines Version Extension also shows how to update fields in various JSON file formats.

I have no experience of OneDrive config files or intune so can't offer any more assistance

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