JakeBentz

ESX_Host_Audit.ps1

Jan 31st, 2013
176
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # /=======================================================================
  2. # /=
  3. # /=  ESX_Host_Audit.ps1
  4. # /=
  5. # /=  AUTHOR: Jake Bentz
  6. # /=  DATE: 01/29/2013
  7. # /=
  8. # /=  REQUIREMENTS: N/A
  9. # /=
  10. # /=  DESCRIPTION: This script audits settings on all ESX hosts in the esxservers.txt textfile
  11. # /=
  12. # /=  REVISION HISTORY
  13. # /=   VER  DATE        AUTHOR/EDITOR   COMMENT
  14. # /=   1.0  01/29/2013   Jake Bentz  Created script
  15. # /=
  16. # /=======================================================================#
  17. #
  18. # Create log folder if it doesn't exist
  19. $Logpath = ".\Output"
  20. If ((Test-Path -Path $Logpath) -ne $true) { New-Item -ItemType directory -Path $Logpath}
  21. #
  22. # Add VI-toolkit #
  23. Add-PSsnapin VMware.VimAutomation.Core
  24. Initialize-VIToolkitEnvironment.ps1
  25. # Get root credential
  26. $rootPassword = Read-Host ìEnter root passwordî -AsSecureString
  27. $rootCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist ìrootî,$rootPassword
  28.  
  29.  # Get list of Host servers from textfile to run audit on
  30.  Get-Content esxservers.txt | %{
  31.   Connect-VIServer $_ -User root -Password $rootCredential.GetNetworkCredential().Password -ErrorAction SilentlyContinue -ErrorVariable ConnectError | Out-Null
  32.   If ($ConnectError -ne $Null) {
  33.    Write-Host ìERROR: Failed to connect to ESX server:î $_
  34.    $Output = "ERROR: Failed to connect to ESX server: "
  35.    $Output = $Output += $_
  36.    Write $Output >> $Logfile
  37.   }
  38.   Else {
  39.     # Create log file
  40.     $Logfile = ".\Output\"+ $_ + (get-date -format '_dd_MMM_yyyy_hhmm') +".txt"
  41.     Write "================================================================" > $Logfile
  42.         $HostName = "ESX Host Audit Settings Report for "
  43.         $HostName = $HostName += $_
  44.     Write $Hostname >> $Logfile
  45.     Write "================================================================" >> $Logfile
  46.         $ReportGen = "Report generated on "
  47.         $ReportGen = $ReportGen += (get-date -format 'MMM dd, yyyy ')
  48.         $ReportGen = $ReportGen += "by "
  49.         $ReportGen = $ReportGen += $env:username
  50.     Write $ReportGen >> $Logfile
  51.     Write "================================================================" >> $Logfile
  52.     $HostReport = @()
  53.     Get-VMHost |%{    
  54.         #   $Report = "" | select Hostname, version, Build, manufacture, Model,cpu_model, core_num, totalmemoryMB, ip_address,vmotion_ip, HBA_num, P_nic
  55.         $Report = "" | select Hostname, version, Build, cpu_model, core_num, totalmemoryMB, ip_address,vmotion_ip, HBA_num, P_nic
  56.             $Report.Hostname = $_.Name
  57.             $Report.version =$_.Version
  58.             $Report.Build =$_.Build
  59.         #   $Report.manufacture =$_.ExtensionData.Hardware.SystemInfo.Vendor
  60.         #   $Report.Model =$_.Model
  61.             $Report.cpu_model =$_.ExtensionData.Summary.Hardware.CpuModel
  62.             $Report.core_num =$_.ExtensionData.Hardware.CpuInfo.NumCpuCores
  63.             $Report.totalmemoryMB =$_.MemoryTotalMB
  64.         if($Report.version -like "3.5.*"){
  65.           $Report.ip_address =$_.ExtensionData.Config.Network.ConsoleVnic.Spec.ip.ipaddress
  66.         }
  67.      else {$Report.ip_address =$_.ExtensionData.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress}
  68.         $Report.vmotion_ip =$_.ExtensionData.Config.Vmotion.IpConfig.IpAddress
  69.         $Report.HBA_num =$_.ExtensionData.Summary.Hardware.NumHBAs
  70.         $Report.P_nic =$_.ExtensionData.Config.Network.Pnic.count
  71.      $HostReport += $Report
  72. }
  73. #$HostReport | Export-Csv $Logfile ñNoTypeInformation
  74. Write $HostReport >> $Logfile
  75. Write-Host "Report generated for " $_
  76.       Disconnect-VIServer -Confirm:$False | Out-Null
  77.   }
  78.  }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment