VMWARE SCRIPTING

Set syslog server for all hosts in vCenter:
Get-VMHost | Set-VMHostAdvancedConfiguration -Name Syslog.global.logHost -Value syslogserver.domain.com

Configure VMHost hostd and vpxa logging levels
Get-VMHost | Get-AdvancedSetting -Name “Config.HostAgent.log.level”,”Vpx.Vpxa.config.log.level” | Set-AdvancedSetting -Value “info” -Confirm:$false

Reload syslog service on ESXi host:
$hosts = Get-VMHost
foreach($vihost in $hosts){
$esxcli = get-vmhost $vihost | Get-EsxCli
$esxcli.system.syslog.reload()
}

Open firewall for syslog:
Get-VMHost | Get-VMHostFirewallException | where {$_.Name.StartsWith(‘syslog’)} | Set-VMHostFirewallException -Enabled $true

Check Change Block Tracking status for all VMs:
Get-VM | where {$_.Powerstate -eq “PoweredON”} | Get-View | Sort Name | Select Name, @{N=”ChangeTrackingStatus”;E={$_.Config.ChangeTrackingEnabled}}

Attach NFS datastore to all hosts in specific data center:
get-datacenter -Name MyDataCenter | Get-VMHost | New-Datastore -Nfs -Name MyNFSDatastore -Path “/mynfs” -NfsHost myfnsserver.domain.com

Shutdown all VMs in the cluster:
Get-Cluster ClusterName | Get-VM | ? {$_.PowerState -eq ‘PoweredOn’} | Shutdown-VMGuest -Confirm

Get SSH service status for hosts
Get-VMHost | Get-VMHostService | Where { $_.Key -eq “TSM-SSH” } |select VMHost, Label, Running

Start SSH service
Get-VMhost | Get-VMHostService | ? {($_.Key -eq “TSM-SSH”) -and ($_.Running -eq $False)} | Start-VMHostService

Stop SSH service
Get-VMhost | Get-VMHostService | ? {($_.Key -eq “TSM-SSH”) -and ($_.Running -eq $True)} | Stop-VMHostService

Stop SSH servive on all hosts in cluster and suppress confirmation
Get-Cluster Cluster1 | Get-VMHost | ForEach {Stop-VMHostService -HostService ($_ | Get-VMHostService | Where {$_.Key -eq “TSM-SSH”}) -Confirm:$FALSE}

List all services on hosts and their running status
Get-VMhost  | Get-VMHostService | select Key,Label,Running

Display NTP servers and Running status
Get-VMHost | Select-Object Name,@{Name=”NTPServer”;Expression={$_ | Get-VMHostNtpServer}}, @{Name=”NTPRunning”;Expression={($_ | Get-VMHostService | Where-Object {$_.key -eq “ntpd”}).Running}} | Sort-Object -Property “NTPRunning”, “NTPServer”

Display the multipath policy for all LUN’s connected to all hosts in cluster
Get-Cluster  | Get-VMHost | Get-ScsiLun -LunType disk

Display the multipath policy for all LUN’s connected to host
Get-VMHost | Get-ScsiLun -LunType disk

Sets the multipath policy for all EMC LUN’s connected to all hosts in Cluster RV00 to roundrobin
Get-Cluster  | Get-VMHost | Get-ScsiLun -CanonicalName “naa.6006*” | Set-ScsiLun -MultipathPolicy “roundrobin”

Sets the multipath policy for all EMC LUN’s connected to host
Get-VMHost  | Get-ScsiLun -CanonicalName “naa.6006*” | Set-ScsiLun -MultipathPolicy “roundrobin”

Output the CanonicalName for all the devices on cluster that are EMC type (naa.6006*)
Get-Cluster  | Get-VMHost | Get-ScsiLun -CanonicalName “naa.6006*” | fl -show CanonicalName | out-file c:\shared\naa-id.txt

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s