Magic Quadrant™ für Privileged Access Management 2025: Netwrix zum vierten Jahr in Folge anerkannt. Laden Sie den Bericht herunter.

Plattform
Ressourcen­zentrumBlog
So sammeln Sie AD Site-Informationen mithilfe von PowerShell

So sammeln Sie AD Site-Informationen mithilfe von PowerShell

Jul 20, 2017

A good old PowerShell will help you in case you wish to collect AD site information such as Active Directory site location, site options configured, ISTG assigned to the site, Site links and bridgehead servers. Below PowerShell Script uses New-Object function to connect to Directory Context and then get all Active Directory sites. All Active Directory sites are stored in a variable. Script uses ForEach loop to traverse through each site stored in the variable and then append the site information in a CSV file.

      $ReportFile = "C:TempADSiteInfo.CSV"
Remove-item $ReportFile -ErrorAction SilentlyContinue
$ThisString="AD Site,Location,Site Option,Current ISTG,Subnets,Servers,In Site Links,Bridgehead Servers"
Add-Content "$ReportFile" $ThisString

$CurForestName = "Netwrix.com"
$a = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext("Forest", $CurForestName)
[array]$ADSites=[System.DirectoryServices.ActiveDirectory.Forest]::GetForest($a).sites
$ADSites
ForEach ($Site in $ADSites)
{
    $SiteName = $Site.Name
    $SiteLocation = $site.Location
    $SiteOptions = $Site.Options
    $SiteISTG = $Site.InterSiteTopologyGenerator

    [array] $SiteServers = $Site.Servers.Count
    [array] $SiteSubnets = $Site.Subnets.Count
    [array] $SiteLinks = $Site.SiteLinks.Count
    [array] $SiteBH = $Site.BridgeheadServers.Count

    $FinalVal=$SiteName+","+'"'+$SiteLocation+'"'+","+'"'+$SiteOptions+'"'+","+$SiteISTG+","+$SiteSubnets+","+$SiteServers+","+$SiteLinks+","+$SiteBH
    Add-Content "$ReportFile" $FinalVal          
}
      

Nachdem das obige PowerShell-Skript ausgeführt wurde, haben Sie Informationen für jede Active Directory-Site in der Datei „C:TempADSiteInfo.CSV“ gespeichert. Beachten Sie, dass das Skript standardmäßig mit dem aktuellen Active Directory Forest verbunden wird. Falls Sie den Speicherort der Berichtsdatei ändern möchten, passen Sie bitte die Variable $ReportFile an.

Benötigen Sie mehr PowerShell-Skripte für Active Directory? Finden Sie alle am meisten gewünschten PowerShell-Befehle für Active Directory in einem Blogbeitrag.

Teilen auf

Erfahren Sie mehr

Über den Autor

Asset Not Found

Nirmal Sharma