Created
November 27, 2019 15:42
-
-
Save sunnyc7/7d042db51ac598420be0bf6814486d39 to your computer and use it in GitHub Desktop.
This is a perennial issue when you are trying to run inventory based on AD, and not count all the Cluster objects.
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
| Function Test-IfServerIsCluster { | |
| <# | |
| .Synopsis | |
| Test if an AD Object is a Cluster | |
| .INPUT | |
| Input Object requires PsComputerName, ServicePrincipalName AD Attributes | |
| $test = get-qadcomputer VDICLU001 -IncludedProperties 'ServicePrincipalName' | select Name,ServicePrincipalName | |
| $test = get-qadcomputer VDICLU001 -OSName "Windows Server*" -SizeLimit -1 -IncludedProperties 'ServicePrincipalName' | select Name,ServicePrincipalName | |
| .EXAMPLE | |
| $item = get-qadcomputer -OSName "Windows Server*" -SizeLimit -1 -IncludedProperties 'ServicePrincipalName' | select Name,ServicePrincipalName | |
| Test-IfServerIsCluster -computerObj $item | |
| .OUTPUTS | |
| Name IsCluster SPN | |
| ---- --------- --- | |
| VDICLU001 CLUSTER {MSServerCluster/VDICLU001, MSServerClusterMgmtAPI/VDICLU001, MSClusterVirtualServer/VDICLU001, HOST/VDICLU001...} | |
| #> | |
| [OutputType([Bool])] | |
| [cmdletbinding()] | |
| param( | |
| $computerObj | |
| ) | |
| begin { | |
| #ClusterSPN Test Checker | |
| $cluSPNString = '^MSClusterVirtualServer' | |
| } | |
| process { | |
| if ($computerObj.servicePrincipalName) { | |
| $spnArray = $computerObj.servicePrincipalName -split "," | |
| # Split SPN's and check each SPN for $cluSPNString. There maybe multiple matches | |
| $clusterTest = foreach ($item in $spnArray) { | |
| #Write-Host -ForegroundColor Cyan -Object $item | |
| if ($item -match $cluSPNString) { | |
| #$Matches[0] | |
| $true | |
| } | |
| else { | |
| $false | |
| } | |
| } | |
| } | |
| # CHCECK IF any one of the SPN's is True. This is tricky, as multiple SPN's can return true | |
| if ($true -in $clusterTest) { | |
| "CLUSTER" | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment