# /======================================================================= # /= # /= ESX_Host_Audit.ps1 # /= # /= AUTHOR: Jake Bentz # /= DATE: 01/29/2013 # /= # /= REQUIREMENTS: N/A # /= # /= DESCRIPTION: This script audits settings on all ESX hosts in the esxservers.txt textfile # /= # /= REVISION HISTORY # /= VER DATE AUTHOR/EDITOR COMMENT # /= 1.0 01/29/2013 Jake Bentz Created script # /= # /=======================================================================# # # Create log folder if it doesn't exist $Logpath = ".\Output" If ((Test-Path -Path $Logpath) -ne $true) { New-Item -ItemType directory -Path $Logpath} # # Add VI-toolkit # Add-PSsnapin VMware.VimAutomation.Core Initialize-VIToolkitEnvironment.ps1 # Get root credential $rootPassword = Read-Host ìEnter root passwordî -AsSecureString $rootCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist ìrootî,$rootPassword # Get list of Host servers from textfile to run audit on Get-Content esxservers.txt | %{ Connect-VIServer $_ -User root -Password $rootCredential.GetNetworkCredential().Password -ErrorAction SilentlyContinue -ErrorVariable ConnectError | Out-Null If ($ConnectError -ne $Null) { Write-Host ìERROR: Failed to connect to ESX server:î $_ $Output = "ERROR: Failed to connect to ESX server: " $Output = $Output += $_ Write $Output >> $Logfile } Else { # Create log file $Logfile = ".\Output\"+ $_ + (get-date -format '_dd_MMM_yyyy_hhmm') +".txt" Write "================================================================" > $Logfile $HostName = "ESX Host Audit Settings Report for " $HostName = $HostName += $_ Write $Hostname >> $Logfile Write "================================================================" >> $Logfile $ReportGen = "Report generated on " $ReportGen = $ReportGen += (get-date -format 'MMM dd, yyyy ') $ReportGen = $ReportGen += "by " $ReportGen = $ReportGen += $env:username Write $ReportGen >> $Logfile Write "================================================================" >> $Logfile $HostReport = @() Get-VMHost |%{ # $Report = "" | select Hostname, version, Build, manufacture, Model,cpu_model, core_num, totalmemoryMB, ip_address,vmotion_ip, HBA_num, P_nic $Report = "" | select Hostname, version, Build, cpu_model, core_num, totalmemoryMB, ip_address,vmotion_ip, HBA_num, P_nic $Report.Hostname = $_.Name $Report.version =$_.Version $Report.Build =$_.Build # $Report.manufacture =$_.ExtensionData.Hardware.SystemInfo.Vendor # $Report.Model =$_.Model $Report.cpu_model =$_.ExtensionData.Summary.Hardware.CpuModel $Report.core_num =$_.ExtensionData.Hardware.CpuInfo.NumCpuCores $Report.totalmemoryMB =$_.MemoryTotalMB if($Report.version -like "3.5.*"){ $Report.ip_address =$_.ExtensionData.Config.Network.ConsoleVnic.Spec.ip.ipaddress } else {$Report.ip_address =$_.ExtensionData.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress} $Report.vmotion_ip =$_.ExtensionData.Config.Vmotion.IpConfig.IpAddress $Report.HBA_num =$_.ExtensionData.Summary.Hardware.NumHBAs $Report.P_nic =$_.ExtensionData.Config.Network.Pnic.count $HostReport += $Report } #$HostReport | Export-Csv $Logfile ñNoTypeInformation Write $HostReport >> $Logfile Write-Host "Report generated for " $_ Disconnect-VIServer -Confirm:$False | Out-Null } }