Pages

Showing posts with label vmware. Show all posts
Showing posts with label vmware. Show all posts

11/18/2016

VMWare Workstation Networking

This is a great overview of how networking works in VM Workstation:
rednectar: vmware-interfaces-tutorial

The diagrams are especially helpful:


1/15/2014

Check Time on VMWare Hosts

Check Time on VMware Hosts Similar to my previous script reporting on Windows Server time.

##########################################################################################
# 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=@'
<STYLE>
BODY{font-family: Verdana, Arial, Helvetica, sans-serif;font-size:12;font-color: #000000}
TABLE{border-width: 2px;padding: 1px;border-style: solid;border-color: black;border-collapse: collapse;} 
TH{border-width: 2px;padding: 1px;border-style: solid;border-color: black;background-color: #dddddd;font-size:16;font-weight:bold}
TD{border-width: 2px;padding: 2px;border-style: solid;border-color: black;background-color: #efefef; font-size:12;font-weight:normal} 
TD.error{border-width: 2px;padding: 2px;border-style: solid;border-color: black;background-color: #ffffff;font face="monospace";font-size:10;font-color: #cccccc}
</STYLE> 
<HTML> 
<HEAD> 
<TITLE></TITLE> 
</HEAD> 
<BODY> 
<H2>VMWare Host Time Issues</H2> 
<H4>
'@
$report+=$today
$report+="</H4><table><th>Server</th><th>Date</th><th>Time</th><th>Off(s)</th></tr>"

############################################################################################
# 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+='<tr><td class="error">' + $comp + '</td>' 
    $report+='<td colspan="4" class="error">' + "ERROR - No response to date/time query" + '</td>'  
   $report+='</tr>' 
  continue
  } # end if output
 }#end if ping
 else { # No PING response
  write-host "$computer`tERROR:  No PING Response"
   $report+='<tr><td class="error">' + $comp + '</td>' 
          $report+='<td colspan="4" class="error">' + "CONNECTION ERROR:  No response to PING" + '</td>'  
   $report+='</tr>' 
  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+=('<tr><td>' + $comp + '</td>') 
    $report+=('<td >' + $d + '</td>')  
    $report+=('<td >' + $t + '</td>')  
    $report+=('<td >' + $diff + '</td>')  
    $report+=('</tr>') 
    }
  }# end if null 
}#end foreach computer
###
$report+="</TABLE></BODY></HTML>" 

$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

11/07/2013

HL Tools - Part 1 - Clone a VM without vCenter | LucD notesLucD notes

HL Tools - Part 1 - Clone a VM without vCenter | LucD notesLucD notes: Clone a VM without vCenter

HL Tools - Part 2 - Create a Nested Hypervisor | LucD notesLucD notes

HL Tools - Part 2 - Create a Nested Hypervisor | LucD notesLucD notes: Create a Nested Hypervisor

Simple Host Time Information

Simple Host Time Information

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

Exporting all that useful VM information with PowerCLI » WoodITWork.com

Exporting all that useful VM information with PowerCLI » WoodITWork.com: Exporting all that useful VM information with PowerCLI

dvSwitch scripting - Part 13 - Export/Restore Config | LucD notesLucD notes

dvSwitch scripting - Part 13 - Export/Restore Config | LucD notesLucD notes: One of the exciting new dvSwitch features in vSphere 5.1 is the ability to export and restore a dvSwitch configuration.

This article explains how to do that in Powershell

Cheap disaster recovery using PowerShell

Cheap disaster recovery using PowerShell: Cheap disaster recovery

Poor mans SRM

InventorySnapshot – VMware Labs

InventorySnapshot – VMware Labs: InventorySnapshot allows a user to “snapshot” a given vCenter inventory configuration and then reproduce it.

7/16/2013

VMWare Powershell NTP Service Setup

VMware Powershell NTP Service Setup


#####################################################################
#
#   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

7/10/2013

Powershell: Count datastores on VMWare Hosts

Powershell: Count datastores on VMware Hosts

All the LUN mappings & datastore names need to match on all hosts in a cluster. I hope to someday script a more comprehensive comparison of datastores & names. However, a quick and dirty confirmation is to count the datastores that are connected on every host in each cluster. If they match, it at least gives me a warm feeling.

#####################################################################
#
#   
#        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

Powershell: VMware guest inventory

Powershell: VMware Guest Inventory

Gather information from vCenter server about VM's. In this case I was looking for machines that were connected to more than one network or datastore.

$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

7/02/2013

SYSPREP on cloned Windows Server 2008 R2 Fails

Trouble with sysprep not running when vmware runs customization after deploying a Win2K8R2 template. -> SID for all the clones is the same. Supposedly this matters much less these days but some odd stuff happened that we couldn't explain when we attempted to join to AD domain (NEWSID doesn't work past Win2003) SYSPREP logs are located at: c:\windows\system32\sysprep\panther log files: setupact.log, setuperr.log Apparently sysprep will not run when it thinks Windows has been upgraded in place. This particular template they were copying had several applications installed on it for which we don't know the owner so rebuilding fresh was not an option. The following worked to allow sysprep to run: - Remove the machine from the domain - Registry export: HKLM\SYSTEM\Setup (as backup) - Delete from the registry: HKLM\SYSTEM\Setup\Upgrade - Run: c:\windows\system32\Sysprep\Sysprep.exe /oobe /generalize

3/08/2013

ESXi Remote Administration

Remotely managing ESXi servers has turned into such a pain in the butt. From VCS: - Software > Security Profile - Check firewall and check box for SSH client & server if needed. - Open Services and start the SSH service. - SSH to server - you can type DCUI to get the same user interface as if you are on the console of the physical server. - or you can do the following to restart all the services: - cd /sbin - services.sh restart

2/12/2013

VMware KB: Troubleshooting transaction logs on a Microsoft SQL database server

VMware KB: Troubleshooting transaction logs on a Microsoft SQL database server: Troubleshooting transaction logs on a Microsoft SQL database server
Prevent logs from filling up the server:
  1. Log in to the Microsoft SQL 2005/2008 Server as an administrator.
  2. Open up SQL Management Studio.
  3. Right-click the database that VirtualCenter is using.
  4. Click Properties.
  5. Click the Options link.
  6. Set the Recovery Model to Simple
  7. Click OK.
  8. Once this is complete, right click on the database again.
  9. Click Tasks>Shrink>Files.
  10. On the Shrink Database window select the file type as 'Log' . The file name appears in the filename drop down as databasename_log
  11. The space used versus the space allocated displays. After you set the recovery model to Simple, the majority of the space in the transaction log released.
  12. Ensure that the Release unused space radio button is selected.
  13. Click OK on this window to shrink the transaction log.