A. Mikkelsen VMware ESX scripts, commands, tools and other nice to know things that will make your virtualization days easier!!!!

Sunday, January 31, 2010

vLogView by Xtravirt

Filed under: Tools,vSphere (ESX) — Tags: , , , — A. Mikkelsen @ 23:41 pm

vLogView, helps you view and search all LOG files from each of your ESX hosts from a single application.

For more info and the latest download, visit http://xtravirt.com/xd10132

vlogview

Playing with PowerCLI

Filed under: PowerShell — Tags: , , , , , , , — A. Mikkelsen @ 21:45 pm

Last week I attended a Magirus course on administrating you VMware environment using PowerCLI, and below is some of the small scripts I created.

These code sniplets will help you manage your VMware environment and give you some ideas of how powerful the VMware PowerCLI really is.

I’m sure VMware will add even more CMDLETS to the PowerCLI in the feature.

Get the latest PowerCLI here.
A function to load different PSSnapins.
Put it in the beginning of all you Powershell scripts,
to load the different PSSnapin you need.


function LoadSnapin{
  param($PSSnapinName)
  if (!(Get-PSSnapin | where {$_.Name   -eq $PSSnapinName})){
    Add-pssnapin -name $PSSnapinName
  }
}
LoadSnapin -PSSnapinName   "VMware.VimAutomation.Core"

Clone a VM to template.


$VMToClone = "vm_name"
$TemplateName = "TemplateName"
$Datacenter = "Training"
get-vm $VMToClone| stop-vm
New-Template -VM $VMToClone -Name $TemplateName 
   -Location $(Get-Datacenter $Datacenter)

Convert Template to VM – without changing the name.


$TemplateName = "TemplateName"
Set-Template -Template $(get-template $TemplateName) -ToVM

Convert VM to Template – without changing the name.


$VMtoTemplate = "vm_name"
$vm = Get-VM $VMtoTemplate | Get-View
$vm.MarkAsTemplate()

Deploying a VM from template.


$strNewVMName = "NewVM_01"
$strTemplate = "TemplateName"
$strDestinationHost = "ESX01"
New-VM -Name $strNewVMName -Template $(get-template   $strTemplate) 
   -VMHost $(Get-VMHost $strDestinationHost)

Deploying a VM from template using a Customization Specification and using Thin provisioning.
Make sure the CustomSpec has been created beforehand.


$strNewVMName = "NewVM_01"
$strTemplate = "TemplateName"
$strDestinationHost = "ESX01"
$strCustomSpec = "TEST-CustomSpec"
New-VM -Name $strNewVMName -Template $(get-template $strTemplate) 
   -VMHost $(Get-VMHost $strDestinationHost) -DiskStorageFormat 
   Thin -OSCustomizationSpec $(Get-OSCustomizationSpec $strCustomSpec)

Moving a VM to a specific folder.


$strDistinationFolder = "MyFolder"
$strDatacenter = "Training"
$VMToMove = "MyVM"
move-vm -VM $(get-vm $VMToMove) -Destination $(Get-Folder 
    -Name $strDistinationFolder -Location $(Get-Datacenter $strDatacenter))

Copying a file to a Windows VM (With or without network access)
Requires VMware tools to be running.


$VM = get-vm -name "myVM"
$target = "C:\MY_DIR\"
$source = "C:\MY_DIR\test.txt"
Copy-VMGuestFile -Source $source -Destination $target -vm $VM 
   -LocalToGuest -HostUser "root" -HostPassword "password" 
   -GuestUser "myVM\administrator" -GuestPassword "password" 
   -Force:$true

Copying a file from a Windows VM (With or without network access)
Requires VMware tools to be running.


$VM = get-vm -name "myVM"
$target = "C:\MY_DIR\"
$source = "C:\MY_DIR\test.txt"
Copy-VMGuestFile -Source $source -Destination $target -vm $VM 
   -GuestToLocal -HostUser "root" -HostPassword "password" 
   -GuestUser "myVM\administrator" -GuestPassword "password" 
   -Force:$true

Listing the content of “C:\Windows\System32” from a VM – remotely


$VM = get-vm -name "myVM"
Invoke-VMScript -VM $VM -ScriptText "dir" -HostUser "root" 
   -HostPassword "password" -GuestUser "myVM\administrator" 
   -GuestPassword "password"

Run msinfo32 on a guest VM and pipe the output to a TXT file – Using PowerShell.


$VM = get-vm -name "myVM"
$script = '&"$env:ProgramFiles\Common Files\Microsoft Shared\
   MSInfo\msinfo32.exe" /report "$env:Tmp\inforeport.txt"'
Invoke-VMScript -VM $VM -ScriptText $script -HostUser "root" 
   -HostPassword "password" -GuestUser "myVM\administrator" 
   -GuestPassword "password"

Open the above output file in the guest VM – Using PowerShell.


$VM = get-vm -name "myVM"
$script = '&"notepad.exe" "$env:Tmp\inforeport.txt"'
Invoke-VMScript -VM $VM -ScriptText $script -HostUser "root" 
   -HostPassword "password" -GuestUser "myVM\administrator" 
   -GuestPassword "password" -ScriptType Powershell

Run msinfo32 on a guest VM and pipe the output to a TXT file – Using batch commands.


$VM = get-vm -name "myVM"
$script = '&"%programfiles%\Common Files\Microsoft Shared\
   MSInfo\msinfo32.exe" /report "%tmp%\inforeport.txt"'
Invoke-VMScript -VM $VM -ScriptText $script -HostUser "root" 
   -HostPassword "password" -GuestUser "myVM\administrator" 
   -GuestPassword "password" -ScriptType Bat

Open the above output file in the guest VM – Using batch commands.


$VM = get-vm -name "myVM"
$script = '"notepad.exe"   "%Tmp%\inforeport.txt"'
Invoke-VMScript -VM $VM -ScriptText $script -HostUser "root" 
   -HostPassword "password" -GuestUser "myVM\administrator" 
   -GuestPassword "password" -ScriptType Bat

Wednesday, January 6, 2010

Interpret the output of ESXTOP in vSphere

Filed under: Performance,Troubleshooting,vSphere (ESX) — Tags: , , , , — A. Mikkelsen @ 9:39 am

If you need a good guide to Interpreting the statistic from ESXTOP then take a look at this guide from VMware.

http://communities.vmware.com/docs/DOC-9279

I’m using it to troubleshoot performance issues (poor response times) from clients in different locations, when using the remote console.

Powered by WordPress