Skip to content

Instantly share code, notes, and snippets.

@dampee
Last active June 19, 2023 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dampee/652632dcd9e7e1792d2324c868a5a196 to your computer and use it in GitHub Desktop.
Save dampee/652632dcd9e7e1792d2324c868a5a196 to your computer and use it in GitHub Desktop.
Get all (pre v9) umbraco versions of all websites on a shared server
# Import the WebAdministration module if not already imported
if (-not (Get-Module -ListAvailable -Name WebAdministration)) {
Import-Module WebAdministration
}
# Retrieve the server name
$serverName = $env:COMPUTERNAME
# Retrieve all IIS websites
$websites = Get-Website
# Create an array to store website information
$websiteInfo = @()
# Loop through each website
foreach ($website in $websites) {
$siteName = $website.Name
$physicalPath = $website.PhysicalPath
$webConfigPath = Join-Path -Path $physicalPath -ChildPath "web.config"
if (Test-Path $webConfigPath) {
$xml = New-Object -TypeName System.Xml.XmlDocument
$xml.Load($webConfigPath)
# Retrieve the values of umbracoConfigurationStatus and Umbraco.Core.ConfigurationStatus
$appSettings = $xml.SelectNodes("//appSettings/add")
$umbracoConfigStatus = $appSettings | Where-Object { $_.key -eq "umbracoConfigurationStatus" } | Select-Object -ExpandProperty value
$umbracoCoreConfigStatus = $appSettings | Where-Object { $_.key -eq "Umbraco.Core.ConfigurationStatus" } | Select-Object -ExpandProperty value
# Concatenate the values into a single field
if ([string]::IsNullOrWhiteSpace($umbracoConfigStatus) -or [string]::IsNullOrWhiteSpace($umbracoCoreConfigStatus)) {
$configStatus = "$umbracoConfigStatus$umbracoCoreConfigStatus"
}
else {
$configStatus = "$umbracoConfigStatus | $umbracoCoreConfigStatus"
}
}
else {
$configStatus = "Web.config not found"
}
# Create a custom object with server name, website, and configuration status values
$websiteObject = [PSCustomObject]@{
ServerName = $serverName
Website = $siteName
ConfigurationStatus = $configStatus
}
# Add the website object to the array
$websiteInfo += $websiteObject
}
# Generate timestamp
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
# Construct the filename
$fileName = "sites_$timestamp.csv"
# Export the website information to a CSV file
$exportPath = Join-Path -Path $PSScriptRoot -ChildPath $fileName
$websiteInfo | Export-Csv -Path $exportPath -NoTypeInformation
Write-Host "Website information exported to: $exportPath"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment