AD Health Check

arskatb

AD Health Check

Viesti Kirjoittaja arskatb »

Powershell komento. Ajettava AD:lla
Muokkaa rivejä mikäli tarvetta.
Mukana kaksio koodia.. Nimeä koodi2 nimellä "DC_info"
Molemmat tiedostot paikaan c:\Scripts_PowerShell\

Koodi: Valitse kaikki

function AllDCs 
{ 
    $objRootDSE = New-Object System.DirectoryServices.DirectoryEntry('LDAP://rootDSE') 
    $objSites = New-Object System.DirectoryServices.DirectoryEntry('LDAP://CN=Sites,' + $objRootDSE.configurationNamingContext) 
 
    $strFilter = "(&(objectCategory=Server)(dNSHostName=*))" 
    $objSearcher = New-Object System.DirectoryServices.DirectorySearcher 
    $objSearcher.SearchRoot = $objSites 
    $objSearcher.PageSize = 1000 
    $objSearcher.Filter = $strFilter 
    $objSearcher.SearchScope = "Subtree" 
 
    $colProplist = "dNSHostname", "distinguishedName" 
    foreach ($i in $colPropList) 
    { 
    [void] $objSearcher.PropertiesToLoad.Add($i) 
    } 
 
    $colResults = $objSearcher.FindAll() 
 
    foreach ($objResult in $colResults) 
    { 
    $objItem = $objResult.Properties 
    $objNTDS = New-Object System.DirectoryServices.DirectoryEntry('LDAP://CN=NTDS Settings,' + $objItem.distinguishedname) 
    if ($objNTDS.name -ne $null) {  
        $objItem.dnshostname  
    } 
    } 
} 
 
foreach ($dc in AllDCs) 
{ 
    "==== Processing $dc"  
    "==== Processing $dc"     >> $logfile 
    "" >> $logfile 
     
    # get uptime for the Dc's 
     
    $computers = Get-WMIObject -class Win32_OperatingSystem -computer $dc   
   
    foreach ($system in $computers) {   
       $Bootup = $system.LastBootUpTime   
       $LastBootUpTime = WMIDateStringToDate $bootup   
       $now = Get-Date 
       $Uptime = $now - $lastBootUpTime   
       $d = $Uptime.Days   
       $h = $Uptime.Hours   
       $m = $uptime.Minutes   
       $ms= $uptime.Milliseconds   
   
       "System Up for: {0} days, {1} hours, {2}.{3} minutes" -f $d,$h,$m,$ms >> $logfile 
    }    
     
    "" >> $logfile 
     
    # Now run the DC_Info.ps1 script 
      
    $job = Start-Job -filepath c:\Scripts_PowerShell\DC_info.ps1 -ArgumentList $dc 
    Wait-Job $job 
    Receive-Job $job 
        
    "" >> $logfile 
     
    # Run the diagnostic tools 
     
    "======  Begin tool Dcdiag.exe /test:dns /v /s:$dc   ========================" >> $logfile 
    Dcdiag.exe /test:dns /v /s:$dc >> $logfile 
    "======  Begin tool Dcdiag.exe /v /s:$dc   ==================================" >> $logfile        
    Dcdiag.exe /v /s:$dc >> $logfile 
    "======  Begin tool Repadmin /kcc $dc   =====================================" >> $logfile 
    Repadmin /kcc $dc         >> $logfile 
    "======  Begin tool Repadmin /showrepl   ====================================" >> $logfile 
    Repadmin /showrepl >> $logfile 
    "======  Begin tool Repadmin /replsummary  ==================================" >> $logfile 
    Repadmin /replsummary /errorsonly >> $logfile 
     
    # the lines below can be uncommented and run if you want to force a sync to all DC's 
    #"======  Begin tool Repadmin /syncall /A /e $dc   ==========================" >> $logfile 
    #Repadmin /syncall /A /e $dc >> $logfile 
     
    ""                 >> $logfile 
} 

Koodi: Valitse kaikki

 
 
# Get Information about your Domain Controllers to add to your Logfile  
 
 
$strComputer = $args[0] 
 
# Get Operating System Information 
$colOS =Get-WmiObject -class Win32_OperatingSystem -computername $strComputer 
 
foreach($objComp in $colOS){ 
   $c1 = $objComp.Caption 
   $c2 = $objComp.ServicePackMajorVersion 
 
   "Operating System: {0} and Service Pack Level: {1}" -f $c1,$c2 | Out-File C:\Scripts\logfile.log -append 
 
} 
 
# Get Hardware Information 
 
$objWin32CS = Get-WmiObject -Class Win32_ComputerSystem -namespace "root\CIMV2" -computername $strComputer 
 
foreach ($colhw in $objwin32cs){ 
   $c3 = $colhw.manufacturer 
   $c4 = $colhw.model 
   $c9 = $colhw.TotalPhysicalMemory 
 
   #"Manufacturer: {0} and Model: {1}" -f $c3,$c4 | Out-File C:\Scripts\logfile.log -append 
 
} 
 
# Get Serial number from BIOS 
 
$objwin32B = Get-WmiObject -class  Win32_BIOS  -computername $strComputer 
 
foreach ($colB in $objwin32B){ 
   $c5 = $colB.SerialNumber 
 
   "Manufacturer: {0}, Model: {1} and Serial Number: {2}" -f $c3,$c4,$c5 | Out-File C:\Scripts\logfile.log -append 
 
} 
 
# get processor info 
 
$objWin32P = Get-WmiObject -class "Win32_Processor" -namespace "root\CIMV2" -computername $strComputer 
 
foreach ($strPItem in $objWin32P){ 
  $c6 = $strPItem.Name 
  $c7 = $strPItem.NumberOfCores 
  $c8 = $strPItem.NumberOfLogicalProcessors 
   
  "Processor: {0}, Number of cores: {1} and Number of Logical Processors: {2}" -f $c6,$c7,$c8 | Out-File C:\Scripts\logfile.log -append 
} 
 
# Memory Info 
 
[int]$TotMem = $c9 / 1GB 
#$TotMem = $b1 / 1024 
 
"Total Physical Memory: {0}GB" -f $TotMem | Out-File c:\Scripts\logfile.log -append 
 
# Get Network Info 
 
$objWin32NAC = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -namespace "root\CIMV2" -computername $strComputer -Filter "IPEnabled = 'True'" 
 
foreach ($objNACItem in $objWin32NAC){ 
  [string]$c10 = $objNACItem.IPAddress 
  [string]$C11 = $objNACItem.MACAddress 
   
   "IP Address: {0} and MAC Address: {1} " -f $C10,$c11 | Out-File c:\Scripts\logfile.log -append  
}