Lync – Get-MCsPool

When you look for a simple way to get all Lync Server topology, you probably will do a Get-CsPool command. But here, you don’t see the sites and the output is not coming in a easily readable way.

The script below will let you Show all information at once.

Get-MCsPool will show you your infrastructure in an easy way :

Get-MCsPool

 

Communication Server versions tested
Office Communication Server 2007
Microsoft Lync Server 2010 OK
Microsoft Lync Server 2013 OK

 

function Get-MCsPool{

	foreach ($site in Get-Cssite){ 
		Write-Host "Site : " $site.Displayname "( " -NoNewline -ForegroundColor Green
		if ($site.Description -notlike ""){
			Write-Host $site.Description")" -foregroundcolor Green
		}else{
			Write-Host "No description" -foregroundcolor DarkRed -NoNewline
			Write-Host " )" -foregroundcolor Green
		}
		$pools = $site | select -ExpandProperty pools
		foreach ($pool in $pools){
			$boolDiscovered = $false
			[array]$ServerType = ""
		
			Write-Host "Pool : " $pool -ForegroundColor Cyan -NoNewline
			$services = Get-CsPool $pool | select -ExpandProperty services #Get all services from the current pool
			
			If ($Site.ParentSite -ne $Null){ #SBA
				if ($services.count -ge 2){
					$ServerType += "Survivable Branch Appliance"
					$boolDiscovered = $true
				}else{
					$ServerType += " PSTN Gateway "
					$boolDiscovered = $true
				}
			}else{ #NO SBA
			
				$PoolComputersCount = (get-cspool $pool | select -ExpandProperty computers ).count #Get the computer numbers in a pool
	 			if ($PoolComputersCount -ge 2){ #POOL SERVERS (If there is 2 or more computers
					$findOut = $services -match '.*Registrar:([a-zA-Z]).*'
        			if ($findOut) {
						$ServerType += "Enterprise Edition Pool"
						$boolDiscovered = $true
					}
					$findOut = $services -match '.*PersistentChatService:([a-zA-Z]).*'
        			if ($findOut) {
						$ServerType += "Persistent Chat Pool"
        				$boolDiscovered = $true
					}
					$findOut = $services -match '.*TrustedApplicationPool:([a-zA-Z]).*'
        			if ($findOut) {
						$ServerType += "Trusted Application Pool"
        				$boolDiscovered = $true
					}
					$findOut = $services -match '.*EdgeServer:([a-zA-Z]).*'
        			if ($findOut) {
						$ServerType += "EDGE Pool"
        				$boolDiscovered = $true
					}
			
				}else{ #STANDALONE SERVERS (Only one computer)
	    			$findOut = $services -match '.*Registrar:([a-zA-Z]).*'
        			if ($findOut) {
						$Registrar = $findOut -replace "Registrar:",""
						$ServerType += "Standard Edition Pool"
						$boolDiscovered = $true
        			}
					$findOut = $services -match '.*PstnGateway:([a-zA-Z]).*'
        			if ($findOut) {
						$ServerType += "PSTN Gateway"
        				$boolDiscovered = $true
					}
					$findOut = $services -match '.*EdgeServer:([a-zA-Z]).*'
        			if ($findOut) {
						$ServerType += "EDGE Server"
        				$boolDiscovered = $true
					}
					$findOut = $services -match '.*MonitoringServer:([a-zA-Z]).*'
        			if ($findOut) {
						$ServerType += "Monitoring Server"
        				$boolDiscovered = $true
					}
					$findOut = $services -match '.*ArchivingServer:([a-zA-Z]).*'
        			if ($findOut) {
						$ServerType += "Archiving Server"
        				$boolDiscovered = $true
					}
					$findOut = $services -match '.*WacServer:([a-zA-Z]).*'  #Lync 2013
        			if ($findOut) {
						$ServerType += "Office Web Apps Server"
        				$boolDiscovered = $true
					}else{
						$findOut = $services -match '.*WacService:([a-zA-Z]).*' #Lync 2010
						if ($findOut) {
							$ServerType += "Office Web Apps Server"
        					$boolDiscovered = $true
						}
					}
					$findOut = $services -match '.*TrustedApplicationPool:([a-zA-Z]).*'
        			if ($findOut) {
						$ServerType += "Trusted Application Server"
        				$boolDiscovered = $true
					}
					$findOut = $services -match '.*FileStore:([a-zA-Z]).*'
        			if ($findOut) {
						$ServerType += "File Server"
        				$boolDiscovered = $true
					}
					$findOut = $services -match '.*ApplicationDatabase:([a-zA-Z]).*'
        			if ($findOut) {
						$ServerType += "SQL Server"
        				$boolDiscovered = $true
					}
					$findOut = $services -match '.*PersistentChatServer:([a-zA-Z]).*'
        			if ($findOut) {
						$ServerType += "Persistent Chat Server"
        				$boolDiscovered = $true
					}
				}#End pool or no pool
			
			}#end sba or no sba		
			
			if (!$boolDiscovered){ #If the variable is false, it means the service is unknown
				Write-Host " (N/A)" -ForegroundColor Gray -NoNewline
			}else{#If the variable is true, it means the service was discovered
				foreach ($type in $ServerType){
					if ($type -notlike ""){
						if (($type -like "*Edition*") -or ($type -like "Survivable*")){ #For the main pools, Write in Yellow
							Write-Host " ["$type" ]" -ForegroundColor Yellow -NoNewline
						}else{
							Write-Host " ["$type" ]" -ForegroundColor DarkCyan -NoNewline #For the normal service types, write in darkcyan
						}
					}
				}
			}
			Write-Host "" #Add a return after each line
		}#Close Pools foreach
	}#Close Site foreach
}#Close Get-MCsPool function