Tek bir çıktıda Active Directory bilgisi nasıl alınır? Örneğin, Active Directory’yi yeni bir sunucuya taşımak istiyorsunuz ve AD bilgilerini almak istiyorsunuz. Veya AD’de kaç iş istasyonu, sunucu veya grup bulunduğunu bilmek ister misiniz? Bu yazıda, PowerShell betiği ile Active Directory bilgilerini nasıl alacağınızı öğreneceksiniz.
İçindekiler
- AD bilgilerini alma PowerShell betiği
- AD bilgilerini alma PowerShell komut dosyasını indirin
- AD bilgilerini al PowerShell betiğini çalıştırın
- Son
AD bilgilerini alma PowerShell betiği
Get-ADInfo.ps1 PowerShell betiği aşağıdaki AD bilgilerini alır:
- Bilgisayarlar (İş İstasyonları + Sunucular)
- Iş istasyon -ları
- Sunucu
- Kullanıcı
- Grup
- Active Directory orman adı
- Active Directory orman modu
- Active Directory etki alanı modu
- Active Directory şema sürümü
- FSMO rol sahipleri
AD bilgilerini alma PowerShell komut dosyasını indirin
Get-ADInfo.ps1 PowerShell betiğini indirin ve C:\scripts klasörüne yerleştirin. Komut dosyaları klasörünüz yoksa bir tane oluşturun.
# Get counts of different types of objects in Active Directory $Computers = (Get-ADComputer -Filter * | Measure-Object).Count $Workstations = (Get-ADComputer -Filter { OperatingSystem -notlike "*Server*" } | Measure-Object).Count $Servers = (Get-ADComputer -Filter { OperatingSystem -like "*Server*" } | Measure-Object).Count $Users = (Get-ADUser -Filter * | Measure-Object).Count $Groups = (Get-ADGroup -Filter * | Measure-Object).Count # Get Active Directory Forest information $ADForest = (Get-ADDomain).Forest $ADForestMode = (Get-ADForest).ForestMode $ADDomainMode = (Get-ADDomain).DomainMode # Obtain Active Directory Schema version and translate it to the corresponding Windows Server version $ADVer = Get-ADObject (Get-ADRootDSE).schemaNamingContext -Property objectVersion | Select-Object objectVersion $ADNum = $ADVer -replace "@{objectVersion=", "" -replace "}", "" switch ($ADNum) { '91' { $srv = 'Windows Server 2025' } '88' { $srv = 'Windows Server 2019/Windows Server 2022' } '87' { $srv = 'Windows Server 2016' } '69' { $srv = 'Windows Server 2012 R2' } '56' { $srv = 'Windows Server 2012' } '47' { $srv = 'Windows Server 2008 R2' } '44' { $srv = 'Windows Server 2008' } '31' { $srv = 'Windows Server 2003 R2' } '30' { $srv = 'Windows Server 2003' } } # Display collected information Write-host "Active Directory Info" -ForegroundColor Yellow Write-host "" Write-Host "Computers = $Computers" -ForegroundColor Cyan Write-Host "Workstions = $Workstations" -ForegroundColor Cyan Write-Host "Servers = $Servers" -ForegroundColor Cyan Write-Host "Users = $Users" -ForegroundColor Cyan Write-Host "Groups = $Groups" -ForegroundColor Cyan Write-host "" Write-Host "Active Directory Forest Name = "$ADForest -ForegroundColor Cyan Write-Host "Active Directory Forest Mode = "$ADForestMode -ForegroundColor Cyan Write-Host "Active Directory Domain Mode = "$ADDomainMode -ForegroundColor Cyan Write-Host "Active Directory Schema Version is $ADNum which corresponds to $srv" -ForegroundColor Cyan Write-Host "" Write-Host "FSMO Role Owners" -ForegroundColor Cyan # Retrieve FSMO roles individually $Forest = Get-ADForest $SchemaMaster = $Forest.SchemaMaster $DomainNamingMaster = $Forest.DomainNamingMaster $Domain = Get-ADDomain $RIDMaster = $Domain.RIDMaster $PDCEmulator = $Domain.PDCEmulator $InfrastructureMaster = $Domain.InfrastructureMaster # Display FSMO role owners Write-Host "Schema Master = $SchemaMaster" -ForegroundColor Cyan Write-Host "Domain Naming Master = $DomainNamingMaster" -ForegroundColor Cyan Write-Host "RID Master = $RIDMaster" -ForegroundColor Cyan Write-Host "PDC Emulator = $PDCEmulator" -ForegroundColor Cyan Write-Host "Infrastructure Master = $InfrastructureMaster" -ForegroundColor Cyan
Komut dosyasını çalıştırırken herhangi bir hatayı önlemek için dosyanın engellemesinin kaldırıldığından emin olun. PowerShell betiği çalıştırılırken dijital olarak imzalanmamış hata makalesinde daha fazla bilgi edinin.
Diğer bir seçenek de aşağıdaki kodu kopyalayıp Not Defteri’ne yapıştırmaktır. Get-ADInfo.ps1 adını verin ve C:\scripts klasörüne yerleştirin.
# Get counts of different types of objects in Active Directory $Computers = (Get-ADComputer -Filter * | Measure-Object).Count $Workstations = (Get-ADComputer -Filter { OperatingSystem -notlike "*Server*" } | Measure-Object).Count $Servers = (Get-ADComputer -Filter { OperatingSystem -like "*Server*" } | Measure-Object).Count $Users = (Get-ADUser -Filter * | Measure-Object).Count $Groups = (Get-ADGroup -Filter * | Measure-Object).Count # Get Active Directory Forest information $ADForest = (Get-ADDomain).Forest $ADForestMode = (Get-ADForest).ForestMode $ADDomainMode = (Get-ADDomain).DomainMode # Obtain Active Directory Schema version and translate it to the corresponding Windows Server version $ADVer = Get-ADObject (Get-ADRootDSE).schemaNamingContext -Property objectVersion | Select-Object objectVersion $ADNum = $ADVer -replace "@{objectVersion=", "" -replace "}", "" switch ($ADNum) { '91' { $srv = 'Windows Server 2025' } '88' { $srv = 'Windows Server 2019/Windows Server 2022' } '87' { $srv = 'Windows Server 2016' } '69' { $srv = 'Windows Server 2012 R2' } '56' { $srv = 'Windows Server 2012' } '47' { $srv = 'Windows Server 2008 R2' } '44' { $srv = 'Windows Server 2008' } '31' { $srv = 'Windows Server 2003 R2' } '30' { $srv = 'Windows Server 2003' } } # Display collected information Write-host "Active Directory Info" -ForegroundColor Yellow Write-host "" Write-Host "Computers = $Computers" -ForegroundColor Cyan Write-Host "Workstions = $Workstations" -ForegroundColor Cyan Write-Host "Servers = $Servers" -ForegroundColor Cyan Write-Host "Users = $Users" -ForegroundColor Cyan Write-Host "Groups = $Groups" -ForegroundColor Cyan Write-host "" Write-Host "Active Directory Forest Name = "$ADForest -ForegroundColor Cyan Write-Host "Active Directory Forest Mode = "$ADForestMode -ForegroundColor Cyan Write-Host "Active Directory Domain Mode = "$ADDomainMode -ForegroundColor Cyan Write-Host "Active Directory Schema Version is $ADNum which corresponds to $srv" -ForegroundColor Cyan Write-Host "" Write-Host "FSMO Role Owners" -ForegroundColor Cyan # Retrieve FSMO roles individually $Forest = Get-ADForest $SchemaMaster = $Forest.SchemaMaster $DomainNamingMaster = $Forest.DomainNamingMaster $Domain = Get-ADDomain $RIDMaster = $Domain.RIDMaster $PDCEmulator = $Domain.PDCEmulator $InfrastructureMaster = $Domain.InfrastructureMaster # Display FSMO role owners Write-Host "Schema Master = $SchemaMaster" -ForegroundColor Cyan Write-Host "Domain Naming Master = $DomainNamingMaster" -ForegroundColor Cyan Write-Host "RID Master = $RIDMaster" -ForegroundColor Cyan Write-Host "PDC Emulator = $PDCEmulator" -ForegroundColor Cyan Write-Host "Infrastructure Master = $InfrastructureMaster" -ForegroundColor Cyan
AD bilgilerini al PowerShell betiğini çalıştırın
PowerShell’i yönetici olarak çalıştırın. Ardından, Active Directory bilgilerini toplamak için PowerShell betiğini çalıştırın.
C:\scripts\.\Get-ADInfo.ps1
Organizasyonumuzda çıktı bu şekilde görünüyor.
PowerShell betiği ile Active Directory bilgilerini nasıl alacağınızı öğrendiniz. Active Directory’de çok fazla bilgi vardır ve bilgileri PowerShell veya GUI’de tek tek aramak çok zaman alır. Bir PS komut dosyası çalıştırmak ve hepsini tek bir çıktıda bulundurmak zaman kazandırır ve bakması daha kolaydır.