Last active
September 27, 2017 11:46
-
-
Save lowedown/a935b5f78ab547ab36451e6b9817f877 to your computer and use it in GitHub Desktop.
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
# | |
# Powershell script that reads server role configs from Sitecore's excel file | |
# and checks a specified directory to ensure all config files are set up correctly. | |
# | |
# https://doc.sitecore.net/sitecore_experience_platform/setting_up_and_maintaining/xdb/configuring_servers/configure_a_content_delivery_server | |
# https://doc.sitecore.net/sitecore_experience_platform/setting_up_and_maintaining/xdb/configuring_servers/configure_a_processing_server | |
# | |
# | |
$xlsFile = "c:\temp\Config_Enable-Disable_Sitecore_8.1_upd3.xlsx" | |
$startRow = 10 # Including headline row | |
$endRow = 228 | |
# Columns containing path and file name | |
$filePathColumn = 3 | |
$fileNameColumn = 4 | |
# Column containing the role you want to validate (i.E. Content Delivery, Processing, Reporting) | |
$role = 10 | |
$webroot = "C:\data\wwwroot\CM2" | |
$websiteReplaceValue = "\\website"; | |
Function Read-Excel([string] $xlsFile, [int] $startRow, [int] $endRow, [int] $filePathColumn, [int] $fileNameColumn, [int] $role, [string] $webroot, [string] $websiteReplaceValue, [string] $config, [string] $enabled) { | |
$xl = New-Object -COM "Excel.Application" | |
$xl.Visible = $true | |
$wb = $xl.Workbooks.Open($xlsFile) | |
$ws = $wb.Sheets.Item(1) | |
$roleName = $ws.Cells.Item($startRow, $role).text | |
Write-Output "Validating role '$roleName' on folder '$webroot':"; | |
for ($i = $startRow + 1; $i -le $endRow; $i++) { | |
$path = Join-Path -Path $ws.Cells.Item($i, $filePath).text -ChildPath $ws.Cells.Item($i, $fileName).text | |
$path = $path -replace $websiteReplaceValue, $webroot | |
$enabled = $ws.Cells.Item($i, $role).text | |
Check-ConfigFile $path $enabled | |
} | |
$wb.Close() | |
$xl.Quit() | |
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl) | |
} | |
Function Check-ConfigFile([string] $config, [string] $enabled) { | |
# TODO: handle .disabled and .example | |
if ($enabled -eq "enable") { | |
if ($config.EndsWith(".disabled")) { | |
$config = $config.Replace(".disabled", "") | |
} | |
if ($config.EndsWith(".example")) { | |
$config = $config.Replace(".example", "") | |
} | |
} | |
If (Test-Path $config) | |
{ | |
if ($enabled -eq "disable") { | |
if (-Not $config.EndsWith(".disabled")) { | |
Write-Output "'$config' should be DISABLED" | |
} | |
} else { | |
if ($config.EndsWith(".disabled")) { | |
Write-Output "'$config' should be ENABLED" | |
} | |
} | |
} else { | |
if ($enabled -eq "enable") { | |
Write-Output "'$config' should be ENABLED" | |
} | |
} | |
} | |
Read-Excel $xlsFile $startRow $endRow $filePath $fileName $role $webroot $websiteReplaceValue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment