<# .SYNOPSIS Run DCDIAG on all servers in the domain. Chance the -Server with the domain name and run with a privivledged account. .DESCRIPTION .EXAMPLE Get-DCDIAG -Server "yourdomainname.net" This example runs DCDIAG on all domain controllers in the yourdomainname.net domain and saves the output to text files named dcdiag_.txt. .EXAMPLE Get-DCDIAG -Server "yourdomainname.net" | Out-File -FilePath "dcdiag_output.txt" This example runs DCDIAG on all domain controllers in the yourdomainname.net domain and saves the output to a single text file named dcdiag_output.txt. .INPUTS The Microsoft .NET Framework types of objects (if any) that can be piped to the function or script. You can also include a description of the input objects. .OUTPUTS The Microsoft .NET Framework type of the objects that the cmdlet returns (if any). You can also include a description of the returned objects. .NOTES This script requires the Active Directory module to be installed and available in the PowerShell session. Ensure you have the necessary permissions to run DCDIAG on the domain controllers. The output files will be saved in the current directory where the script is executed. #> Import-Module ActiveDirectory # Get all domain controllers in the domain $domainControllers = Get-ADDomainController -Filter * -Server "yourdomainname.net" foreach ($dc in $domainControllers) { $dcName = $dc.HostName $outputFile = "dcdiag_$dcName.txt" Write-Host "Running DCDIAG on $dcName... Saving to $outputFile" -ForegroundColor Cyan dcdiag /s:$dcName /v | Out-File -FilePath $outputFile -Encoding UTF8 }