Showing posts with label VI Toolkit. Show all posts
Showing posts with label VI Toolkit. Show all posts

2009-11-26

Testing Network Failover with PowerCLI

Two weeks ago I wrote an article about How To Bring Down A Single NIC In ESX?. In that post you could see that in order to test this you had to go into the console of the ESX and run the commands on the console.

Already then I was thinking, why not do this from PowerCLI, without having to log into each host.

So here we go..

For the examples sake:

VI Server vcenter.maishsk.local
ESX Host for Testing esx1.maishsk.local
vmnic for Redundancy test vmnic2

 

   1: function Test-NetworkFO ($vmhost, $vmnic, $switch) {
   2:     
   3:     If ($switch){
   4:     ##Define which NIC should be tested   
   5:     $mynic = Get-VMHostNetworkAdapter -VMHost (get-vmhost $vmhost) | `
   6:     Where-Object { $_.DeviceName -eq $vmnic }   
   7:  
   8:     ##Bring the NIC down   
   9:     Set-VMHostNetworkAdapter -PhysicalNic $mynic -Duplex Half -BitRatePerSecMb 10  
  10:     }
  11:     
  12:     If (-not $switch){
  13:     ##Define which NIC should be tested   
  14:     $mynic = Get-VMHostNetworkAdapter -VMHost (get-vmhost $vmhost) | `
  15:     Where-Object { $_.DeviceName -eq $vmnic }   
  16:  
  17:     ##Bring the NIC back up  
  18:     Set-VMHostNetworkAdapter -PhysicalNic $mynic -AutoNegotiate
  19:     }
  20: }
  21:  
  22: # Turn it on
  23: Test-NetworkF0 "vcenter.maishsk.local" "vmnic2" $true
  24:  
  25: # Turn it off
  26: Test-NetworkF0 "vcenter.maishsk.local" "vmnic2" $false


This is a way to test your Network Redundancy for your ESX hosts.

I would like to thank Alan Renouf - who helped me clean up the code and put it into a function.

Have a happy Thanksgiving and a good weekend!

2009-04-22

Say Hello to vSphere PowerCLI

So all the buzz have quieted down – I think have approx 600% less traffic coming in through Twitter than I had yesterday.

All the news about the products names – version changes etc. etc. But I do not recall that there was a mention of one small but extremely important part that will also undergo changes.

The SDK’s and Toolkits.

This I got from the VMware Developer Center Blog. What is new in vSphere SDKs &Toolkits....

SDK

Say goodbye to the to the old VI Toolkit and the RCLI and welcome the new names for our old and trusted tools

2008-11-16

Changing Custom Notes on Virtual Machines

I wanted to do a bit of housekeeping for all the VM's floating around.

I got to the state that there are machines that I do not know who they belong to, when they were installed and who is the responsible party in case the **** hits the fan.

That is where the VI toolkit comes to the rescue !!

What I did was added to addiditonal fields for each machine.

1. Owner
2. Date installed

This was pretty each to do both

Create the field

Get-cluster <Clustername>| get-vm | New-CustomField -name Owner
Get-cluster <Clustername>| get-vm | New-CustomField -name "Date installed"


Now to populate the field you would use

get-vm <VM Name>| Set-CustomField -name Owner -value "Whatever you want"

Now say you don't know which property it is you would like to update, well that you can get from running this command:

PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> get-vm <VM Name>| Get-View


Capability           : VMware.Vim.VirtualMachineCapability
Config               : VMware.Vim.VirtualMachineConfigInfo
Layout               : VMware.Vim.VirtualMachineFileLayout
EnvironmentBrowser   : VMware.Vim.ManagedObjectReference
ResourcePool         : VMware.Vim.ManagedObjectReference
ResourceConfig       : VMware.Vim.ResourceConfigSpec
Runtime              : VMware.Vim.VirtualMachineRuntimeInfo
Guest                : VMware.Vim.GuestInfo
Summary              : VMware.Vim.VirtualMachineSummary
Datastore            : {VMware.Vim.ManagedObjectReference}
Network              : {VMware.Vim.ManagedObjectReference}
Snapshot             :
GuestHeartbeatStatus : green
Parent               : VMware.Vim.ManagedObjectReference
CustomValue          : {10}
OverallStatus        : green
ConfigStatus         : green
ConfigIssue          : {}
EffectiveRole        : {-1}
Permission           : {}
Name                 : <VM Name>
DisabledMethod       : {Destroy_Task, UnregisterVM, RevertToCurrentSnapshot_Task, RemoveAllSnapshots_Task...}
RecentTask           : {}
DeclaredAlarmState   : {alarm-15.vm-3208, alarm-4.vm-3208, alarm-5.vm-3208}
TriggeredAlarmState  : {}
Value                : {10}
AvailableField       : {Date Installed, Owner}
MoRef                : VMware.Vim.ManagedObjectReference
Client               : VMware.Vim.VimClient


AvailableField       : {Date Installed, Owner} is what you are looking for. These are the fields that you are looking to update.

Thanks to LucD for pointing me in the right direction here and here.

My next step will be to create a script that will run daily, and update any VM that has not been populated with the date installed field - with the current date. Maybe even go as far as to send a reminder email to the Cluster Admin to update the owner in the correct field.

Will Let you know how it turns out.