tests/Test-CmDpNoGroups.ps1
function Test-CmDpNoGroups { [CmdletBinding()] param ( [parameter()][string] $TestName = "DP Servers Not in a DP Group", [parameter()][string] $TestGroup = "configuration", [parameter()][string] $Description = "Check for DPs which are not in a DP group", [parameter()][hashtable] $ScriptParams ) try { $startTime = (Get-Date) [System.Collections.Generic.List[PSObject]]$tempdata = @() # for detailed test output to return if needed $stat = "PASS" # do not change this $except = "WARNING" $msg = "No issues found" # do not change this either $query = "SELECT ServerName FROM v_DistributionPointInfo WHERE GroupCount < 1" if ($null -ne $ScriptParams.Credential) { $res = @(Invoke-DbaQuery -SqlInstance $ScriptParams.SqlInstance -Database $ScriptParams.Database -Query $query -SqlCredential $ScriptParams.Credential) } else { $res = @(Invoke-DbaQuery -SqlInstance $ScriptParams.SqlInstance -Database $ScriptParams.Database -Query $query) } if ($null -ne $res -and $res.Count -gt 0) { $stat = $except $msg = "$($res.Count) items found: $($res.ServerName -join ',')" $res | Foreach-Object {$tempdata.Add($_.ServerName)} } } catch { $stat = 'ERROR' $msg = $_.Exception.Message -join ';' } finally { Write-Output $([pscustomobject]@{ TestName = $TestName TestGroup = $TestGroup TestData = $tempdata Description = $Description Status = $stat Message = $msg RunTime = $(Get-RunTime -BaseTime $startTime) Credential = $(if($ScriptParams.Credential){$($ScriptParams.Credential).UserName} else { $env:USERNAME }) }) } } |