Deploy OVA with PowerCLI

It has been a while since I have written anything for my blog. Life has become crazy busy for me the last few months. Between normal work and family time I do not have a lot of free time. The following meme really sums up my life right now.

I have had to deploy a few OVA recently, but wanted to let those that are a little less technical have an easy quick way to accomplish this. Its not that complicated of a script, but it works and gets the job done. By using the Read-Host capability it allows user input into a Powershell script which can really expand Powershells capabilities.

connect-viserver “Your vCenter”

$vmSource = Read-Host – Prompt “File path to OVA”

$vmCluster = Get-Cluster – Name “Name of Cluster you want to use”

$vmHost = ($vmCluster | Get-VMHost)

$vmDatastore = Get-Datastore -Name “Name of Datastore to be used”

$vmName = Read-Host -Prompt “What to name VM?”

$vmHost | Import-vApp – Source $vmSource -Location $vmCluster -Datastore $vmDatastore -Name $vmName -Force

Transferring Files Using PowerCLI

I recently had a unique issue in that I needed to transfer some files to VM’s that were running in a secure environment. This meant there was no network access in our out of this environment except the one used by VMware Tools.  There is a powershell command that can be used to transfer files by utilizing VMware Tools.  This is very useful when transferring files even if it is not a secure environment.

Copy-VMGuestfile -Source “C:\Path\” -Destination “C:\Path\” -VM VMName -LocalToGuest -GuestUser “domain\user” -GuestPassword “password”

If you want to retrieve the file then replace -LocalToGuest with -GuestToLocal

One issue you may encounter is when you have multiple VM’s with the same name.  If they are using different folders then you can point to the correct folder path.

-VM $(Get-VM -Name VMName -Location folder)

Set NTP on all host in vCenter

Here is a Powershell script that will set NTP on all the ESX host connected to your vCenter.

First connect to the vCenter using Connect-VIserver then run the following code.

 

#Get Host
write-host “Gathering ESX Host”
$esx = get-vmhost

#Configure NTP server
write-host “configuring NTP”
Add-VmHostNtpServer -VMHost $esx -NtpServer 10.10.16.220

#Allow NTP queries outbound through the firewall
wrtie-host “Setting Firewall Permissions”
Get-VMHostFirewallException -VMHost $esx | where {$_.Name -eq “NTP client”} | Set-VMHostFirewallException -Enabled:$true

#Start NTP client service and set to automatic
write-host “Starting NTP service”
Get-VmHostService -VMHost $esx | Where-Object {$_.key -eq “ntpd”} | Start-VMHostService
Get-VmHostService -VMHost $esx | Where-Object {$_.key -eq “ntpd”} | Set-VMHostService -policy “automatic”

 

Default Isolation Address

If a host thinks it is isolated by default it will ping its gateway.  It is best practice to have more than one isolation address, and you can have up to 10 of these.  Duncan Epping has a good article on it here.  Here is a simple script I found somewhere on the web.

$cluster = Get-Cluster -Name ITN

New-AdvancedSetting -Entity $cluster -Type ClusterHA -Name ‘das.isolationaddress1’ -Value 1.2.3.4

New-AdvancedSetting -Entity $cluster -Type ClusterHA -Name ‘das.usedefaultisolationaddress’ -Value false

#Disable and reenable HA

Set-Cluster -Cluster $cluster -HAEnabled:$false

Set-Cluster -Cluster $cluster -HAEnabled:$true

Using PowerCLI to change the Syslog server for your ESX host.

I recently discovered SexiLog to use with VMware ESX host.  I needed a quick and easy way to change where the ESX host sent there logs to.  Doing some google searches I was able to put together a quick PowerCLI script.  In about 5 minutes I was able to change the syslog for all of my ESX host.

$ESXLOG = “1.2.3.4”
Get-VMHost | Foreach {
Write-Host “Adding $ESXLOG as Syslog server for $($_.Name)”
$SetSyslog = Set-VMHostSysLogServer -SysLogServer $ESXLOG -SysLogServerPort 514 -VMHost $_
Write-Host “Reloading Syslog on $($_.Name)”
$Reload = (Get-ESXCLI -VMHost $_).System.Syslog.reload()
Write-Host “Setting firewall to allow Syslog out of $($_)”
$FW = $_ | Get-VMHostFirewallException | Where {$_.Name -eq ‘syslog’} | Set-VMHostFirewallException -Enabled:$true
}

Using Solution Enabler to Delete a Storage Group

Recently I have been working on cleaning up storage on a EMC VMAX3.  You can do a lot using the GUI for most of the day to day maintenance, but using the CLI is a lot more efficient when it comes to removing storage groups.

symsg -sid 1234 delete storgegroup_SG -force

Using that command is a simpler and quicker way to remove storage groups than to use the Unisphere GUI.

Using PowerCLI to retrieve Snapshots

Forgetting about snapshots can lead to serious issues.   Not only does the snapshot make the VM perform slower, but it can lead to space issues on the datastore.  You can use PowerCLI to find out what snapshots you have in your vCenter enviroment.

Run PowerCLI and connect your your vCenter instance. Then run these commands

Get-VM | Get-Snapshot | Select, VM, Name, Description.

Blog at WordPress.com.

Up ↑