Public/Get-DomainInventory.ps1
|
function Get-DomainInventory { [CmdletBinding()] param( [ValidateScript({ Test-Path $_ })] [string]$ExportPath = $script:Config.ExportPath, [switch]$SkipUsers, [switch]$SkipComputers, [switch]$SkipGroups ) if (-not (Initialize-Environment)) { Write-Log "Environment initialization failed" -Level Error return } if (-not (Import-ADModule)) { Write-Log "AD Module import failed" -Level Error return } $startTime = Get-Date Write-Log "Starting AD Inventory at $startTime" -Level Info try { $totalSteps = 3 $currentStep = 0 # Get Forest and Domain Info Show-ProgressHelper -Activity "AD Inventory" ` -Status "Getting Forest and Domain Info" ` -PercentComplete (($currentStep / $totalSteps) * 100) Invoke-WithRetry -ScriptBlock { $forest = Get-ForestInfo $domain = Get-DomainInfo } $currentStep++ # Run selected components if (-not $SkipUsers) { Show-ProgressHelper -Activity "AD Inventory" ` -Status "Processing Users" ` -PercentComplete (($currentStep / $totalSteps) * 100) Get-ADUsers -Export -ExportPath $ExportPath | Out-Null $currentStep++ } if (-not $SkipComputers) { Show-ProgressHelper -Activity "AD Inventory" ` -Status "Processing Computers" ` -PercentComplete (($currentStep / $totalSteps) * 100) Get-ADComputers -Export -ExportPath $ExportPath | Out-Null $currentStep++ } if (-not $SkipGroups) { Show-ProgressHelper -Activity "AD Inventory" ` -Status "Processing Groups" ` -PercentComplete (($currentStep / $totalSteps) * 100) Get-ADGroupsAndMembers -Export -ExportPath $ExportPath | Out-Null $currentStep++ } Show-ProgressHelper -Activity "AD Inventory" -Status "Complete" -Completed $endTime = Get-Date $duration = $endTime - $startTime Write-Log "AD Inventory completed. Duration: $($duration.TotalMinutes) minutes" -Level Info } catch { Write-Log "Error during inventory: $($_.Exception.Message)" -Level Error Show-ErrorBox "Error during inventory process" } } |