Functions/PoShMon.Monitoring.SharePoint/Get-ServersInSPFarm.ps1
Function Get-ServersInSPFarm { [CmdletBinding()] Param( [hashtable]$PoShMonConfiguration ) #try #{ $remoteSession = Connect-PrimaryServer -PoShMonConfiguration $PoShMonConfiguration -InitiationScriptBlock { Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue } # Auto-Discover Servers $serverNames = Invoke-Command -Session $remoteSession -ScriptBlock { Get-SPServer | Where Role -ne "Invalid" | Select -ExpandProperty Name } return $serverNames #} catch { # throw $_.Exception #} finally { # if ($remoteSession -ne $null) # { Disconnect-PSSession $remoteSession -ErrorAction SilentlyContinue | Out-Null } #} } |