profile for Gajendra D Ambi on Stack Exchange, a network of free, community-driven Q&A sites

Tuesday, December 30, 2014

AIO Powercli Script for Esxi hosts of a vCenter

watch out for the updates on
https://docs.google.com/document/d/19wPb-pUe9dwTzzvwk1O_4ygDNqn0PXN0o0yzf5kahAU/edit?usp=sharing

#AIO Script[tested ok]###
#Start of Script
############################################
#Configure DNS
#Configure NTP,
#Configure Domain
#Configure Dump Collector
#NFS settings
#TCP settings
#VAAI settings
#compiled by: MrAmbiG
############################################
#prompt for vCenter details
$VC = Read-Host “vCenter IP?”
$VCuser = Read-Host “vCenter administrator username?”
$VCpass = Read-Host “vCenter Password?”
#connect to vCenter
Connect-VIServer $VC -User $VCuser -Password $VCpass -SaveCredentials
Write-Verbose "connecting to vCenter" -foregroundcolor Cyan
#prompt for DNS, Domain, Dump Collector, NTP information
$dns1 = read-host "Primary DNS address?"
$dns2 = read-host "Secondary DNS address?"
$ntp1 = read-host "Primary NTP address?"
$ntp2 = read-host "Secondary NTP address?"
$domain = read-host "The Domain name (hint: vce.local)?”
$dump = read-host "Dump Collector's address (hint: VUM IP)?"
$NFSsettings = read-host "If you want to include NFS settings then type 1 or else type 0"
$TCPsettings = read-host "If you want to include TCP settings then type 1 or else type 0"
$VAAIsettings = read-host "If you want to include the VAAI settings then type 1 or else type 0"
#listing hosts
$esxHosts = get-VMHost
#looping the script for each host
foreach ($esx in $esxHosts)
{
Write-Host "Configuring DNS and Domain Name on $esx" -ForegroundColor Magenta
Get-VMHostNetwork -VMHost $esx | Set-VMHostNetwork -DomainName $domain -SearchDomain $domain -DNSAddress $dns1 , $dns2 -Confirm:$false
Write-Host "Configuring NTP Servers on $esx" -ForegroundColor Green
Add-VMHostNTPServer -NtpServer $ntp1 , $ntp2 -VMHost $esx -Confirm:$false
Write-Host "Configuring NTP Client Policy on $esx" -ForegroundColor Green
Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Set-VMHostService -policy "on" -Confirm:$false
Write-Host "Restarting NTP Client on $esx" -ForegroundColor Blue
Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Restart-VMHostService -Confirm:$false
Write-Host "Configuring Dump Collector on $esx" -BackgroundColor Blue -ForegroundColor Gray
$esxcli = Get-EsxCli -vmhost $esx
$esxcli.system.coredump.network.set($null,“vmk0",$dump,6500)
$esxcli.system.coredump.network.set(1)
$esxcli.system.coredump.network.get()
}
###NFS Settings
if ($NFSsettings -eq '1')
{
Write-host "Including NFS Settings" -BackgroundColor Blue -ForegroundColor Green
foreach ($esx in $esxHosts)
{
Set-AdvancedSetting -VMHost $esx -Name NFS.HeartbeatMaxFailures -Value 10 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name NFS.HeartbeatFrequency -Value 12 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name NFS.HeartbeatTimeout -Value 5 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name NFS.MaxVolumes -Value 256 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name NFS.HeartbeatTimeout -Value 5 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name NFS.HeartbeatDelta -Value 5 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name Disk.UseDeviceReset -Value 0 -Confirm:$false
Write-Host -ForegroundColor Green "VAAI Setting Configured  on $esx"
}
}
else
{
Write-host "NFS Settings" -ForegroundColor RED
}
###TCP Settings
if ($TCPsettings -eq '1')
{
Write-host "Including TCP Settings" -BackgroundColor Green -ForegroundColor Gray
foreach ($esx in $esxHosts)
{
Write-Host "Configuring TCP Settings on $esx" -ForegroundColor Magenta
Set-AdvancedSetting -VMHost $esx -Name Net.TcpipHeapSize -Value 32 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name Net.TcpipHeapMax -Value 512 -Confirm:$false
}
}
else
{
Write-host "TCP Settings" -ForegroundColor RED
}
###VAAI Settings
if ($VAAIsettings -eq '1')
{
Write-host "Executing VAAI disable" -ForegroundColor Green
foreach ($esx in $esxHosts)
{
Write-Host -ForegroundColor Yellow "Configuring VAAI Settings on $$esx"
Set-AdvancedSetting -VMHost $esx -Name Disk.UseDeviceReset -Value 0 -Confirm:$false                                   
Set-AdvancedSetting -VMHost $esx -Name DataMover.HardwareAcceleratedMove -Value 0 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name DataMover.HardwareAcceleratedInit -Value 0 -Confirm:$false                                        
Set-AdvancedSetting -VMHost $esx -Name VMFS3.HardwareAcceleratedLocking -Value 0 -Confirm:$false
Write-Host -ForegroundColor Green "VAAI Setting Configured  on $esx"
}
}
else
{
Write-host -ForegroundColor RED "Excluding VAAI disable section"
}
#End Of Script

set DNS, NTP, Domain via powercli on all hosts of a vCenter

#Start of Script
############################################
#Configure DNS
#Configure NTP,
#Configure Domain
#compiled by : MrAmbiG
############################################
#prompt for vCenter details
$VC = Read-Host “vCenter IP?”
$VCuser = Read-Host “vCenter administrator username?”
$VCpass = Read-Host “vCenter Password?”

#connect to vCenter
Connect-VIServer $VC -User $VCuser -Password $VCpass -SaveCredentials
Write-Verbose "connecting to vCenter" -foregroundcolor Cyan

#prompt for DNS, NTP, Domain information
$dns1 = read-host "Enter Primary DNS IP"
$dns2 = read-host "Enter Secondary DNS IP"
$ntp1 = read-host "Enter Primary NTP IP"
$ntp2 = read-host "Enter Secondary NTP IP"
$domain = read-host "Enter the Domain name ex:- vce.local"

#listing hosts
$esxHosts = get-VMHost

#looping the script for each host
foreach ($esx in $esxHosts)
{
Write-Host "Configuring DNS and Domain Name on $esx" -ForegroundColor Magenta
Get-VMHostNetwork -VMHost $esx | Set-VMHostNetwork -DomainName $domain -DNSAddress $dns1 , $dns2 -Confirm:$false

Write-Host "Configuring NTP Servers on $esx" -ForegroundColor Green
Add-VMHostNTPServer -NtpServer $ntp1 , $ntp2 -VMHost $esx -Confirm:$false

Write-Host "Configuring NTP Client Policy on $esx" -ForegroundColor Green
Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Set-VMHostService -policy "on" -Confirm:$false

Write-Host "Restarting NTP Client on $esx" -ForegroundColor Blue
Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Restart-VMHostService -Confirm:$false
}

Write-Host "b33 is all done here, have a good one; End of Script" -foregroundcolor Blue
#End of Script

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Wednesday, December 24, 2014

Syslog Server and Powercli

#Sets a SysLog server on the Host virtual machine host
Set-VMHostSysLogServer -SysLogServer '<syslog ip>:133' -VMHost Host
#End
----------------------------------------------------------------------------------------------------------------------------
#######script for looping#######
#start of script
#replace IP with the vCenter IP
connect-viserver IP
Write-Host "b33 is connected to your server" -foregroundcolor Cyan -backgroundcolor DarkMagenta
#replace the <syslog server ip> with the correct sys log server ip
#default port is 514 but u may replace it with a custom port if desired.
Get-VMHost | Set-VMHostSysLogServer -SysLogServer <syslog server ip> -SysLogServerPort 514
Write-Host "b33 updated the syslog on all the hosts in return for a smile on your face" -foregroundcolor DarkYellow -backgroundcolor DarkBlue
#End of Script
----------------------------------------------------------------------------------------------------------------------------
https://docs.google.com/document/d/1jTrin_2iHqE7QTwbnSLHiejAANMrvl4HaJ_sqYk7ciY/edit?usp=sharing

Unattended vSphere Client Installation

If you ever wanted to install the vsphere client unattended then here is the simple solution.
start /wait <path to the file inside the vpx folder>\VMware-viclient.exe /q /s /w /L1033 /v" /qr /L*v \"%TEMP%\vmvcc.log\""