A while ago I needed a list of every WFE, APP, SQL server in the farm. The SharePoint Central Administration provides list of servers in farm, however it was not useful in my case because I did not have an exclusive WFE servers, but rather I had 2 servers that I call 'WFE' but they run the Foundation Web Application service in addition to other APP services. From SharePoint perspective, these servers are Application servers.
So I wrote the following PowerShell script to give me a list of objects for WFE, APP, SQL and other servers too.
function getListOfWFEServerNames(){
$WfeServers
= New-Object System.Collections.ArrayList$FarmServers = get-spserver
foreach ($Server in $FarmServers){
$WAService = $Server.serviceinstances | where-object { $_.TypeName –eq "Microsoft SharePoint Foundation Web Application"}
$WAServiceOnline = $WAService.Status –eq "Online"
if ($WAServiceOnline){
$WfeServers.add($Server.Name)
}
}
return $WfeServers
}
function getListOfDBServerNames(){
$DBservers
= New-Object System.Collections.ArrayList$cdb = get-spcontentdatabase
foreach ($c in $cdb){
if ($DBservers -notcontains $c.Server){
$DBservers.add($c.Server)
}
}
return $DBservers
}
$AllServers = Get-spserver | select
Name, role
$SPServers = $AllServers |
where-object {$_.role -eq "WebFrontEnd" -or $_.role -eq
"Application"}$wfeserversNames = getListOfWFEServerNames
$WFE = $SPServers | where-object {$wfeserversNames -contains $_.Name}
$APP = $SPServers | where-object {$_.Role –eq “Application”}
$OtherServers = $AllServers | where-object {$_.role -ne "WebFrontEnd" -and $_.role -ne "Application"}
$dbserversNames = getListOfDBServerNames
$DB = $OtherServers | where-object {$dbserversNames -contains $_.Name}
# Output
write-host
"-------------------------------"write-host "WFE servers are:"
$WFE | select Name
write-host "-------------------------------"
write-host "APP servers are:"
$APP | select Name
write-host "-------------------------------"
write-host "DB servers are:"
$DB | select Name
Happy SharePoint administration!