This is a great overview of how networking works in VM Workstation:
rednectar: vmware-interfaces-tutorial
The diagrams are especially helpful:
rednectar: vmware-interfaces-tutorial
The diagrams are especially helpful:
##########################################################################################
# esx-time.ps1
#
# Gather local time and time zone for all servers in AD.
# Report servers with time different from machine on which script is run
# E-Mail report to designated recipient.
#
# Requires vmware power cli
# "set-powercliconfiguration -InvalidCertificateAction Ignore" to ignore cert errors
#
#
##########################################################################################
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
#VCS
$vcs="privcs01" # PRIVDIVC1, PRIDEVVC1, PRIVCSVDI01, SECVCS01
# E-Mail Recipient
$recipient="administrator@DOMAIN.com"
# Greatest acceptable time difference
$maxdiff=59
$outfile = "c:\dev\esx-time.html"
$user = "usa\svc_vmware"
$pw = Read-Host "Password for $user" -AsSecureString
$rootpw = Read-Host "Password for root" -AsSecureString
#convert $pw to plain text
$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($pw))
#convert $rootpw to plain text
$rootpass = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($rootpw))
############################################################################################
# Get List of Host Names from VCS server
#
write-host "Getting Server List from VCS"
connect-viserver -Server $vcs -User $user -Password $pass -ErrorAction SilentlyContinue > $null
$hosts = get-vmhost
disconnect-viserver -confirm:$false -ErrorAction SilentlyContinue > $null
$list = @()
foreach ($Server in $hosts) {
$Server = $Server -replace "\s{2,}", ""
$Server = $Server -replace "\.usa\.DOMAIN\.com", ""
if ($Server) { $list = $list + $Server } #skip a null value
}
$list = $list | sort-object
write-host "COMPLETE"
###
#clear-host
$today = get-date
############################################################################################
# Report Heading
$report=@'
VMWare Host Time Issues
'@
$report+=$today
$report+="
Server Date Time Off(s) "
############################################################################################
# Query every server in list
write-host "Checking each server:"
foreach ($item in $list) {
$flag=" "
$dt=""
$srvtime=""
$hour = ""
$min = ""
$sec = ""
$month = ""
$day = ""
$year = ""
$comp = ""
$d = ""
$t = ""
$computer = $item
$comp = "{0,-16}" -f $computer
$comp = $comp.padright(16," ")
write-host ">$computer<"
If (Test-Connection -computername $computer -Quiet -count 1){ #respond to ping?
write-host " PING - SUCCESS"
write-host " Time Query"
$output=""
$block = @'
$machine = $args[0]
$pass = $args[1]
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
connect-viserver -server $machine -user "root" -password $pass -WarningAction SilentlyContinue -ErrorAction SilentlyContinue > $null
# $time = (get-view serviceinstance).CurrentTime()
# $time
((get-view serviceinstance).CurrentTime())
'@
$sb = [scriptblock]::create($block)
$args=@()
$args = ($computer, $rootpass)
start-job -name $computer -scriptblock $sb -argumentlist $args > $null
Wait-Job -name $computer -Timeout 60 > $null
$output = Receive-Job $computer
#$output
#disconnect-viserver -server $computer -confirm:$false #-ErrorAction SilentlyContinue > $null
if ($output) {
$dt = $output
write-host "DT=$dt"
}
else {
write-host "$computer`tERROR: No time Query Output"
$report+='' + $comp + ' '
$report+='' + "ERROR - No response to date/time query" + ' '
$report+=' '
continue
} # end if output
}#end if ping
else { # No PING response
write-host "$computer`tERROR: No PING Response"
$report+='' + $comp + ' '
$report+='' + "CONNECTION ERROR: No response to PING" + ' '
$report+=' '
continue
}
[string] $month = [System.Convert]::ToString($dt.Month)
$month = $month.padleft(2,"0")
[string] $day = [System.Convert]::ToString($dt.Day)
$day = $day.padleft(2,"0")
[string] $year = [System.Convert]::ToString($dt.Year)
$year = $year.padleft(4,"0")
$d = $month + "/" + $day + "/" + $year
write-host " Date=$d"
[string] $hour = [System.Convert]::ToString($dt.Hour)
$hour = $hour.padleft(2,"0")
[string] $min = [System.Convert]::ToString($dt.Minute)
$min = $min.padleft(2,"0")
[string] $sec = [System.Convert]::ToString($dt.Second)
$sec = $sec.padleft(2,"0")
$t = $hour + ":" + $min + ":" + $sec
write-host " Time=$t"
if ($dt) { #$dt not null
$srvtime=($dt.Minute)*60+($dt.Second)
$refmin = ""
$refsec = ""
$now = get-date
$cmptime = ($now.Minute)*60+($now.Second)
[string] $min = [System.Convert]::ToString($now.Minute)
$refmin = $min.padleft(2,"0")
[string] $sec = [System.Convert]::ToString($now.Second)
$refsec = $sec.padleft(2,"0")
$reftime=$refmin+":"+$refsec
#Compare server time to script machine time.
$diff=$cmptime-$srvtime
write-host " Time Diff=$diff"
if (($diff -gt $maxdiff) -or ($diff -lt (-1*$maxdiff))) { $flag="*" }
write-host "$flag$comp`t$d`t$t`t$flag$diff$flag`t" $timezone.Description
if ($flag -eq "*") { #time difference is too great
$report+=('' + $comp + ' ')
$report+=('' + $d + ' ')
$report+=('' + $t + ' ')
$report+=('' + $diff + ' ')
$report+=(' ')
}
}# end if null
}#end foreach computer
###
$report+="
"
$report | out-file $outfile
############################################################################################
#e-mail the report
$messageSubject = "VMWare Host Time Report"
$smtpServer = "smtp.DOMAIN.com"
$smtpFrom = "noreply@DOMAIN.com"
$smtpTo = $recipient
$message = $report
send-mailmessage -to $smtpTo -from $smtpFrom -subject $messageSubject -body $message -smtpserver $smtpServer -BodyAsHtml
###
remove-job * -force
Get-VMHost | Sort Name | Select Name, `
@{N="NTPServer";E={$_ |Get-VMHostNtpServer}}, `Timezone, `
@{N="CurrentTime";E={(Get-View $_.ExtensionData.ConfigManager.DateTimeSystem) | Foreach {$_.QueryDateTime().ToLocalTime()}}}, `
@{N="ServiceRunning";E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq "ntpd"}).Running}} `
| Format-Table -AutoSize
#####################################################################
#
# Setup NTP on a new host
#
$vcs = Read-Host "vCenter"
$user = Read-Host "userid"
$pw = Read-Host "Password for $user" -AsSecureString
#convert $pw to plain text
$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($pw))
connect-viserver -Server $vcs -User $user -Password $pass
$pass = " "
clear-host
foreach ($VMHost in (Get-VMHost -Name privh*)) {
" $VMHost"
$ntp=get-vmhostservice -vmhost $VMHost | Where {$_.Key -eq 'ntpd'}
" $ntp"
set-vmhostservice -hostservice $ntp -policy "automatic"
restart-vmhostservice $ntp -confirm:$false
}
disconnect-viserver -confirm:$false
#####################################################################
#
#
# Gather count of LUNs/Datastores connected to all hosts
#
$vcs = Read-Host "vCenter"
$user = Read-Host "userid"
$pw = Read-Host "Password for $user" -AsSecureString
#convert $pw to plain text
$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($pw))
connect-viserver -Server $vcs -User $user -Password $pass
$pass = " "
$today = get-date
$day = $today.Day
$mth = $today.Month
$year = $today.Year
$hour = $today.Hour
$min = $today.Minute
$sec = $today.Second
$date = "$year-$mth-$day-$hour$min$sec"
$outfile = ".\datastores-"+$vcs+"-"+$date+".csv"
clear-host
"Host-Name,Datastore-Count" | out-file $outfile -encoding ascii
foreach ($VMHost in (Get-VMHost -Location $Cluster)) {
" $VMHost"
$dstores = $VMHost | Get-Datastore
$ds = $dstores.count
" $ds"
"$VMHost,$ds" | out-file $outfile -encoding ascii -append
}
disconnect-viserver -confirm:$false
$vcs = Read-Host "vCenter"
$user = Read-Host "userid"
$pw = Read-Host "Password for $user" -AsSecureString
#convert $pw to plain text
$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($pw))
#$vcon = Disconnect-VIServer * -Confirm:$False
$vcon = connect-viserver -Server $vcs -User $user -Password $pass
$pass = " "
$outfile = ".\"+$vcs+"-info.csv"
$reportedvms=New-Object System.Collections.ArrayList
$vms=get-view -viewtype virtualmachine | Sort-Object -Property {$_.Config.Hardware.Device | where {$_ -is [VMware.Vim.VirtualEthernetCard]} | Measure-Object | select -ExpandProperty Count} -Descending
foreach($vm in $vms){
$status = $vm.name
" $status"
$reportedvm = New-Object PSObject
$ipnum = ($vm.guest.net | select IPaddress).IPaddress| out-string
$path = $vm.name
$current = get-view $vm.parent
do {
$parent = $current
if($parent.Name -ne "Datastore*"){$path = $parent.Name + "\" + $path}
$current = Get-View $current.Parent
} while ($current.Parent -ne $null)
Add-Member -Inputobject $reportedvm -MemberType noteProperty -name Path -value $path
# Add-Member -Inputobject $reportedvm -MemberType noteProperty -name Guest -value $vm.Name
Add-Member -Inputobject $reportedvm -MemberType noteProperty -name Networks -value $($vm.network.count)
Add-Member -Inputobject $reportedvm -MemberType noteProperty -name Network -value $((get-view $vm.network).name)
Add-Member -Inputobject $reportedvm -MemberType noteProperty -name IP -value $ipnum
Add-Member -Inputobject $reportedvm -MemberType noteProperty -name Datastores -value $($vm.datastore.count)
Add-Member -Inputobject $reportedvm -MemberType noteProperty -name Datastore -value $((get-view $vm.datastore).name)
$networkcards =$vm.guest.net
Add-Member -Inputobject $reportedvm -MemberType noteProperty -name Nics -value $($networkcards.count)
Add-Member -Inputobject $reportedvm -MemberType noteProperty -name Disks -value $($vm.guest.disk.count)
$reportedvms.add($reportedvm) |Out-Null
}
$reportedvms|Export-Csv $outfile
Disconnect-VIServer * -Confirm:$False