Difference between revisions of "ESX Script Extracts and Examples"

Jump to navigation Jump to search
→‎ESX BIOS, NIC and HBA Driver Versions: Added PowerShell_Credentials_Files template, remove refs to Log (standard.ps1) and VC_List
m (→‎Daily ESX Up/Down Check: Added PowerShell_Credentials_Files template)
(→‎ESX BIOS, NIC and HBA Driver Versions: Added PowerShell_Credentials_Files template, remove refs to Log (standard.ps1) and VC_List)
Line 162: Line 162:
$start = Get-Date
$start = Get-Date
$OutputFile = "ESXs.csv"
$OutputFile = "ESXs.csv"
$VC_List = "ESX-Check.csv"
$UserFile = "User.fil"
$UserFile = "User.fil"
$PassFile = "Pass.fil"                          # Encrypted file to store password in
$PassFile = "Pass.fil"                          # Encrypted file to store password in
$Results = @()
$Results = @()


# Include library files
$VCs = @()
. .\lib\Standard.ps1
$VCs += "vCentreA"                              # Hostname of Virtual Center
$VCs += "vCentreB"                              # Hostname of Virtual Center (repeat if you have more VC's, delete if you've only one)


Start-Transcript -Path ESX-Inventory.log
Start-Transcript -Path ESX-Inventory.log
Log "Started script run at $start"
Write-Host "Started script run at $start"


# Function-U-like ===================================================================================
# Function-U-like ===================================================================================
Line 183: Line 183:


# ===================================================================================================  
# ===================================================================================================  
# Load list of VC's
try {
    $VCs = Import-CSV $VC_List
} catch {
    Log "ERROR: Failed to load list of vC's"
    Exit
}


# Load password credential from encrypted file
# Load password credential from encrypted file
Line 201: Line 193:
     # Connect to VC
     # Connect to VC
     try {
     try {
         Log("Connecting to " + $vc.vc)
         Log("Connecting to " + $vc)
         $VCconn = Connect-VIServer -Server $vc.vc -Credential $cred -errorAction "Stop"
         $VCconn = Connect-VIServer -Server $vc -Credential $cred -errorAction "Stop"
     } catch [VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidLogin] {
     } catch [VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidLogin] {
         Log("Unable to connect to vCentre, invalid logon error !!")
         Log("Unable to connect to vCentre, invalid logon error !!")
Line 213: Line 205:
      
      
     # Get ESX objects
     # Get ESX objects
     Log("Getting list of ESXs to check on " + ($vc.vc) + "...")
     Log("Getting list of ESXs to check on " + ($vc) + "...")
     $ESXs = Get-VMHost -Server $vc.vc | Sort -property Name
     $ESXs = Get-VMHost -Server $vc | Sort -property Name
     Log("Got list of " + ($ESXs.Count) + " ESXs to check")  
     Log("Got list of " + ($ESXs.Count) + " ESXs to check")  
      
      
Line 226: Line 218:
          
          
         # Get the basics
         # Get the basics
         $row.VC = $vc.vc
         $row.VC = $vc
         $row.Cluster = $ESX.Parent
         $row.Cluster = $ESX.Parent
         $row.Name = $ESX.Name.Split(".")[0]
         $row.Name = $ESX.Name.Split(".")[0]
Line 285: Line 277:
          
          
</source>
</source>
{{PowerShell_Credentials_Files}}


== Daily ESX Up/Down Check ==
== Daily ESX Up/Down Check ==

Navigation menu