Thursday 22 June 2017

Creating a pester script with powershell

I’m knocking up a few more infrastructure validation tests and couldn’t be bothered to write everything, so with the quick script it gets you a starting point, creating a simple test for each value that ends with ver (version).

Obviously this needs further work, but not a bad starting point.

$results = Get-ItemProperty -Path "HKLM:\Software\Wow6432Node\TrendMicro\PC-cillinNTCorp\CurrentVersion\Misc."

foreach ($property in $results.PSObject.Properties) {
    if ($property.Name -like '*Ver') {
        write-host "It `"$($property.Name) has a valid version`" {"
        Write-Host "    `$results.$($property.Name) | Should Be `"$($property.Value)`""
        Write-Host "}"
        Write-Host
    }
}

No comments:

Post a Comment