How to find the Master Browser using Power Shell

 Function Global:Get-BrowseMaster {
 [cmdletbinding()]
 Param(
 [String]$LocalMachine ="$Env:COMPUTERNAME",
 [Switch]$All
 )
 Begin{
 Clear-Host
 $x = 0
        }
 Process{
 $Discovery = NBTStat -a $LocalMachine | Out-String -Stream | Select-String "MSBrowse"
 If($Discovery -match "MSBrowse") {
 Write-Host "$LocalMachine is the Browse master" -BackgroundColor Magenta ;$x =1
                                        }
 If($x -ne 1 -or $All) {
 $NetworkComputer =switch -RegEx (NET.EXE VIEW) {
 "^\\(?\S+)\s+" {$matches.Name}
                                                                             }
 Clear-Host
 Foreach($LocalMachine in $NetworkComputer) {
 $Discovery = NBTStat -a $LocalMachine | Out-String -Stream | Select-String "MSBrowse"
 If($Discovery -match "MSBrowse") {
 Write-Host "$LocalMachine is the Browse Master" -BackgroundColor Magenta
                                               }
 Else  {
 "$LocalMachine is an imposter"
              }
           } # End of Foreach
       } # End of If
    } # End of Process
 } # End of Function Get-BrowseMaster
 Get-BrowseMaster

Leave a Reply

Your email address will not be published. Required fields are marked *