Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Function ExtractSite {
Param([string]$source, [string]$destination)
$webConfigPath = Join-Path -Path $destination -ChildPath "Web.config"
$isUpgrade = Test-Path $destination;
if ($isUpgrade) {
$webConfigBackupPath = Join-Path -Path $destination -ChildPath ("Web.config.{0}.bak" -f (Get-Date).Ticks)
$webConfig = [xml](Get-Content ($webConfigPath) -Encoding UTF8)
$previousVersion = ($webConfig.configuration.appSettings.add | Where-Object { $_.key -eq "umbracoConfigurationStatus" }).value
$previousConnectionString = ($webConfig.configuration.connectionStrings.add | Where-Object { $_.name -eq "umbracoDbDSN" }).connectionString
$previousSqlProvider = ($webConfig.configuration.connectionStrings.add | Where-Object { $_.name -eq "umbracoDbDSN" }).providerName
$machineKey = $webConfig.configuration["system.web"].machineKey
Copy-Item $webConfigPath -Destination $webConfigBackupPath
#Waiting for locks to be released
Start-Sleep -Seconds 60
}
Expand-Archive -LiteralPath (Get-Item $source).FullName -DestinationPath $destination -Force
if ($isUpgrade) {
$webConfig = [xml](Get-Content ($webConfigPath) -Encoding UTF8)
($webConfig.configuration.appSettings.add | Where-Object { $_.key -eq "umbracoConfigurationStatus" }).value = $previousVersion;
($webConfig.configuration.connectionStrings.add | Where-Object { $_.name -eq "umbracoDbDSN" }).connectionString = $previousConnectionString;
($webConfig.configuration.connectionStrings.add | Where-Object { $_.name -eq "umbracoDbDSN" }).providerName = $previousSqlProvider;
if ($null -ne $machineKey) {
$node = $webConfig.ImportNode($machineKey, $true);
$webConfig.configuration["system.web"].AppendChild($node) | Out-Null;
}
$webConfig.Save($webConfigPath)
}
Success
}
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.