Script revision host ESXi – PowerCli

Hola!

Aqui tenéis el script, en PowerCli, para revisar que todos los host de tu vCenter cumplan tu standard y tengas un entorno homogeneo. Si necesitais agregar algún parametro a revisar lo podemos añadir.

Parametros:

Versión ESXi
DNS
SSH (Activo y sin alarma)
NTP
Cantidad de vlans
Cantidad de DTS
Cluster

Código (de momento copialo y pegalo en un notepad o notepad ++ para poder leerlo mejor)

—————————————————————————————————————-

 

<#

Scrip para la comprobación del vcenter:

Nos conectamos al vcenter en cuestion (Connect-VIServer)
 Nos situamos en la ruta donde tengamos el script
 Ejecutamos ./CheckHost.ps1
 Esperamos a que termine y comprobamos en el excel que realiza para ver donde teniamos problemas.
 Para estar seguro de que todo esta correcto se puede lanzar otra vez.

#>

cls

#Declaramos variables

$vmhost = get-vmhost | select | % {$_.name}
 $vmhostname = get-vmhost | select Name
 $Random = $vmhost | get-Random
 $vcenterlarge = Get-VMHost $Random| get-view | % {$_.client.ServiceUrl}
 $vcenter = $vcenterlarge.Substring(8,24)

Write-host Check del vCenter $vcenter -foregroundcolor yellow
 Write-host ""
 Write-host Revisamos version host
 Write-host     "    " -Comprobar que todos tengan la misma version
 Write-host ""
 Write-host Revisamos DNS
 Write-host     "    " -Nuestro DNS: ********
 Write-host ""
 Write-host Revisamos SSH
 Write-host     "    " -Si el valor de SSHalarm es 1: es correcto
 Write-host ""
 Write-host Revisamos NTP
 Write-host "    " En Policy, si aparece ON esta correcto.
 Write-host ""
 Write-host Revisamos el numero de VLAN.
 Write-host "    " Ojo! Si el host es de Admin tendra menos vlan
 Write-host ""
 Write-host Revisamos el numero de DTS.
 Write-host ""
 Write-host Revisamos a que CLUSTER pertenece.
 Write-host ""

$Report2 = @()
 foreach ($item in $vmhostname)
 {

$CheckINFO = {} | Select Name,Version,DNS,SSHrunning,SSHpolicy,SSHalarm,NTPenabled,NTPrunning,NTPpolicy,NTPip,NumVLAN,NumDTS,Cluster

$Name = $item.name
 $DNS = ***************
 $NTP = ***************

$CheckINFO.Name = $name

$numbuild = Get-VMHost $name | get-view | % {$_.Config.Product.FullName}
 $build = $numbuild.Substring(31,7)
 $numversion = $numbuild.Substring(7,10)
 [string]$CheckINFO.version = $numversion,$build

$CheckINFO.DNS = Get-VMHost $name | Get-VMHostNetwork | Select | % {$_.DNSAddress}

$VLAN = Get-VirtualPortGroup -VMHost $name | Where-Object {$_.Name -match "vlan"} | select name
 $CheckINFO.NumVLAN = $VLAN.count

$DTS = Get-VMHost $name | Get-Datastore | select name
 $CheckINFO.NumDTS = $DTS.count

$CheckINFO.Cluster = Get-VMHost $name | get-cluster | select | % {$_.name}

if ($CheckINFO.DNS -ne "$DNS") {Write-host "El dns del servidor $name esta incorrecto, generando ps1 para solucion..." -foregroundcolor magenta

Get-VMHostNetwork -VMHost $name | Set-VMHostNetwork -DomainName ad.bbva.com -DNSAddress $DNS -Confirm:$false | out-null

}

$CheckINFO.SSHrunning = get-vmhost $name | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} | select | % {$_.Running}
 if ($CheckINFO.SSHrunning -ne "Running") {Write-host "La configuracion SSH (Servicio Parado) en $name no es correcta, solucionando..." -foregroundcolor magenta

Get-vmhost $name | Foreach {Start-VMHostService -HostService ( $_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} )} | out-null

}
 $CheckINFO.SSHpolicy = get-vmhost $name | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} | select | % {$_.Policy}
 if ($CheckINFO.SSHpolicy -ne "on") {Write-host "La configuracion SSH (Arranque Automatico) en $name  no es correcta, solucionando..." -foregroundcolor magenta

Get-VMHost $name | Foreach {Get-VMHostService -VMHost $name | Where-Object {$_.Key -eq "TSM-SSH"} | Set-VMHostService -policy "on" -Confirm:$false}  | out-null

}
 $CheckINFO.SSHalarm = get-vmhost $name | Get-AdvancedSetting | Where {$_.Name -eq "UserVars.SuppressShellWarning"} | select | % {$_.value}
 if ($CheckINFO.SSHalarm -ne "1") {Write-host "La configuracion SSH (Alerta Sumary) en $name  no es correcta, solucionando..." -foregroundcolor magenta

Get-VMHost $name | Get-AdvancedSetting | Where {$_.Name -eq "UserVars.SuppressShellWarning"} | Set-AdvancedSetting -Value "1" -Confirm:$false | out-null

}
 $CheckINFO.NTPenabled = Get-VMHostFirewallException -VMHost $name | where {$_.Name -match "NTP"} | select | % {$_.Enabled}
 if ($CheckINFO.NTPenabled -ne "True") {Write-host "La configuracion NTP (Cliente Parado) en $name no es correcta, solucionando..." -foregroundcolor magenta

Get-VMHostFirewallException -VMHost $name | where {$_.Name -match "NTP"} | Set-VMHostFirewallException -Enabled:$true | out-null

}

$CheckINFO.NTPrunning = get-vmhost $name | Foreach {Start-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "ntpd"} )} | select | % {$_.Running}
 if ($CheckINFO.NTPrunning -ne "Running") {Write-host "La configuracion NTP (Servicio Parado) en $name no es correcta, solucionando..." -foregroundcolor magenta

Get-vmhost $name | Foreach {Start-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "ntpd"} )} | out-null

}

$CheckINFO.NTPpolicy = get-vmhost $name | Foreach {Start-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "ntpd"} )} | select | % {$_.Policy}
 if ($CheckINFO.NTPpolicy -ne "on") {Write-host "La configuracion NTP (Arranque Automatico) en $name no es correcta, solucionando..."    -foregroundcolor magenta

$ntp = Get-VmHostService -VMhost $name | Where {$_.Key -eq 'ntpd'}
 Set-VMHostService -HostService $ntp -policy "on" | out-null

}
 $CheckINFO.NTPip = Get-VMHost $name | Get-VMHostNtpServer
 if ($CheckINFO.NTPip -ne "$NTP") {Write-host "La configuracion NTP (Servidor Correcto) en $name no es correcta, solucionando..." -foregroundcolor magenta

Add-VmHostNtpServer -NtpServer $NTP -VMHost $name -Confirm:$false | out-null

}

Write-host ""
 $Report2 += $CheckINFO

}

Write-host "    "vCenter revisado Todos los host cumplen el standard -foregroundcolor green
 Write-host ""
 $Report2 | Export-Csv vCENTERcompliance.csv -NoTypeInformation

 

—————————————————————————————————————-

Deja un comentario