Last active
June 19, 2023 13:25
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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