Created
November 8, 2016 10:41
-
-
Save markwragg/7d93a51265816780b6451dddf22d6585 to your computer and use it in GitHub Desktop.
Pester tests for validating the configuration of a server matches the configuration captured previously (e.g prior to a change).
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
Get-WmiObject Win32_logicaldisk | Export-Clixml "$env:computername-LogicalDisks.xml" | |
(Get-Service | select name,displayname,status) | Export-Clixml "$env:computername-Services.xml" | |
(Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.IPEnabled -eq "True"}) | Export-Clixml "$env:computername-Network.xml" |
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
Describe "Validating Disk configuration of $env:computername" { | |
Import-Clixml "$env:computername-LogicalDisks.xml" | ForEach-Object { | |
$PrevDisk = $_ | |
$CurrDisk = Get-WmiObject Win32_logicaldisk | Where-Object {$_.DeviceID -eq $PrevDisk.DeviceID} | |
Context "Disk $($PrevDisk.DeviceID) checks" { | |
It "Disk $($PrevDisk.DeviceID) previously existed" { | |
$CurrDisk | Should Be $True | |
} | |
($PrevDisk | Select DeviceID,DriveType,ProviderName,Size,VolumeName).psobject.properties | ForEach-Object { | |
It "Disk $($PrevDisk.DeviceID) $($_.name) was previously $($_.value)" { | |
$CurrDisk."$($_.name)" | Should Be $_.value | |
} | |
} | |
} | |
} | |
} | |
Describe "Validating Service configuration of $env:computername" { | |
$Statuses = @('Running','Stopped') | |
$Statuses | ForEach-Object { | |
$Status = $_ | |
Context "Checking $Status services" { | |
Import-Clixml "$env:computername-Services.xml" | Where-Object {$_.status.value -eq $Status} | ForEach-Object { | |
$PrevService = $_ | |
$CurrService = Get-Service | Where-Object {$_.name -eq $PrevService.name} | |
It "Service '$($PrevService.displayname)' ($($CurrService.name)) was previously $($PrevService.status.value)" { | |
$CurrService.status | Should Be $($PrevService.status.value) | |
} | |
} | |
} | |
} | |
} | |
Describe "Validating Network configuration of $env:computername" { | |
Import-Clixml "$env:computername-Network.xml" | ForEach-Object { | |
$PrevNetwork = $_ | |
$CurrNetwork = (Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.Index -eq $PrevNetwork.Index}) | |
Context "Interface '$($PrevNetwork.Description)' checks" { | |
It "Interface $($PrevNetwork.Description) previously existed" { | |
$CurrNetwork | Should Be $True | |
} | |
($PrevNetwork | Select DHCPEnabled,DHCPServer,DNSDomain,DNSDomainSuffixSearchOrder,DomainDNSRegistrationEnabled,FullDNSRegistrationEnabled,IPAddress,DefaultIPGateway,IPSubnet).psobject.properties | ForEach-Object { | |
It "$($_.name) was previously $($_.value)" { | |
$CurrNetwork."$($_.name)" | Should Be $_.value | |
} | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment