PowerShell ile Active Directory sayısını alma

PowerShell ile Active Directory sayısını alma
Active Directory nesneleri nasıl sayılır ve neden AD nesneleri sayımına ihtiyacımız var? Örneğimizde, Microsoft Entra Connect'i yüklemeden ve yapılandırmadan önce toplam sayıya sahip olmak istiyoruz. Bunun nedeni, minimum sunucu gereksinimleri için toplam AD nesnelerini bilmemiz gerektiğidir. Bu yazıda, PowerShell ile AD nesnelerinin nasıl sayılacağına bakacağız.

İçindekiler

  • AD kullanıcılarını sayma
  • AD gruplarını sayma
  • AD bilgisayarlarını sayma
  • AD toplam sayısını alma
  • PowerShell betiği ile Active Directory bilgilerini alma
  • Son

AD kullanıcılarını sayma

PowerShell ile AD kullanıcılarını sayın. Get-AdUser cmdlet'ini kullanın.
(Get-AdUser -Filter * | Measure-Object).Count 

AD gruplarını sayma

PowerShell ile AD gruplarını sayın. Get-ADGroup cmdlet'ini kullanın.

(Get-ADGroup -Filter * | Measure-Object).Count

AD bilgisayarlarını sayma

PowerShell ile AD bilgisayarlarını sayın. Get-ADComputer cmdlet'ini kullanın.

(Get-ADComputer -Filter * | Measure-Object).Count

AD toplam sayısını alma

PowerShell ile kullanıcı, grup ve bilgisayar sayılarını birlikte ekleyelim. Aşağıdaki betiği kullanın, kopyalayıp PowerShell'e yapıştırın. Ayrıca Get-ADCount.ps1 betiğini indirebilir ve PowerShell'den çalıştırabilirsiniz.
$ADUser = (Get-AdUser -Filter * | Measure-Object).Count $ADGroup = (Get-ADGroup -Filter * | Measure-Object).Count $ADComputer = (Get-ADComputer -Filter * | Measure-Object).Count $ADObjects = $ADUser + $ADGroup + $ADComputer $ADObjects
Komut dosyasını çalıştırdıktan sonra bu şekilde görünür. Toplam AD nesnesi sayısı 167'dir.
PS C:\> $ADUser = (Get-AdUser -Filter *).Count $ADGroup = (Get-ADGroup -Filter *).Count $ADComputer = (Get-ADComputer -Filter *).Count $ADObjects = $ADUser + $ADGroup + $ADComputer $ADObjects 167

PowerShell betiği ile Active Directory bilgilerini alma

Active Directory sayısını almanın mükemmel bir yolu, Get-ADInfo.ps1 PowerShell betiğini çalıştırmaktır. Bu, AD nesnelerinin sayısını ve Active Directory'niz hakkında daha fazla bilgiyi gösterecektir.
# 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
 
Önceki Yazı Microsoft Entra Connect'i PowerShell ile eşitlemeye zorla
Microsoft Entra Connect'i PowerShell ile eşitlemeye zorla

Şirket içi AD nesnelerinde acil değişiklikler yaptık ve bunların Microsoft...

Sonraki Yazı Microsoft Entra Connect sunucusu nasıl bulunur
Microsoft Entra Connect sunucusu nasıl bulunur

Microsoft Entra Connect sunucusu nasıl bulunur? Bazen, Microsoft Entra Connect'...