Tag Archives: PowerCLI

The Onyx has landed

A couple of months ago Carter Shanklin (Product Manager of Automating the World) teased us all with a wonderful application which creates PowerCLI scripts for you by tracing your actions in the vCenter Client.

The scripts it produces are not PowerCLI perfect but they do produce a raw format of a script which can be used to find the awkward bits of the API that are hidden in the back of the API documentation.  The true power in PowerCLI will still be the manipulation of the cmdlets.

Continue reading →

VESI & PowerGUI PowerPack V2

V2 Nodes

As the official download count for V1 of my PowerPack has now hit over 1000 downaloads (I cant thank you all enough), I have now released V2 of my PowerPack for VESI and PowerGUI, this is more like the version I wanted to release first time around.

In the first PowerPack, I took a fair few snippets of code I had written on my blog and added these to the PowerPack to get people interested, now in Version 2 I have added even more content, more nodes, more actions and a fair bit of user requested features.

As you can see from the image on the left, there are a fair few nodes (so many I had to cut and paste the image together as they wouldn’t all fit in one screen capture).

There are also some new actions (see screenshots below).

If you have ESXi hosts you should find this useful, now you will be able to download the current firmware state to your windows machine with the click of a button, deploy it back and also reset them back to default configuration (seen below).

I was also requested to add the vCheck script into this version so you could run ad-hoc reports on customer sites, you will find this under the General tab.

You will also find many more VM nodes, most of which where inspired by Armin van Lieshout who was a great help during the testing phase and even sent through his own code for me to include.  Thanks Armin.

Thanks to the other beta testers who sent me some great feedback (most of which is in here), I couldn’t have done it without you guys !  I also want to thank Kirk Munro who helped me out with a few coding or should I say User errors in V1 of this PowerPack 😉

Continue reading →

vCheck Hypervisor style

The thing I love about adding my work to my site is that some people pick up what I have created and expand on it, I like to think that’s a sign of firstly my scripts being interesting enough to expand and secondly my scripts being so well written that anyone can pick them up and tailor them to their needs.

Following the initial additions that were added to v3 of vCheck, Raphael from http://www.hypervisor.fr/ has expanded my script somewhat further to include even more amazing functionality.

He has added the following areas of reporting:

  • Host Ballooning
  • Datastore Over Allocation
  • Snapshot Oversize
  • VCB garbage
  • VMkernel warning check for ESX/ESXi (with deduplication)
  • invalid or inaccessible VM
  • Inapshot add/remove summary
  • Time build
  • NTP (service only) check

I will certainly make sure these are included in V4 with multiple other entries but in the meantime if you would like to download his excellent version then please check out his site, the posts are in French but he is nice enough to keep the script pure English 😉 Continue reading →

PowerCLI – Where do I start ?!

Recently I have been asked a few times where to start when trying to learn PowerCLI and Powershell, there are many learning resources available for PowerShell, all you need to do is Google “Powershell basics” and off you go but what about PowerCLI ?

Well first on the list would have to be the book ‘Managing VMware Infrastructure with Windows PowerShell’ by Hal Rottenberg.  Its a great book with loads of examples and Hal has a great way of writing where it keeps you amused whilst still learning.

Secondly there is my blog post which takes it right back to basics and tells you how to install PowerCLI.

Thirdly, there are a number of great PDF files which you can read to help you along your journey, starting from the basics up to the more interesting ones including cmdlet references and in depth features:

Continue reading →

vCheck 3.1 ?

Whooops, looks like I got a couple of things wrong and I also missed something out that a few people were asking for, You can call this a minor release. I think you should be able to change these yourselves as they are very straight forward and its not worth me re-issuing the script as you would have to change your preferences again which is actually more work !

Continue reading →

vCheck (Daily Report) V3

Initially when I started this script I wanted people to be clear that this was a report that was going to give you a daily summary of any issues which may exist in your Virtual Infrastructure, from the beta testing I did to a select few it was clear that they were expecting this to send them a full inventory of their infrastructure.

That wasn’t the point in this script and I think people now have the idea that this is more of an issue log than an audit script so I will now revert to my original name of…. vCheck.

The key thing to remember is that if an issue does not exist in a particular area then it will not show in the output, when and if issues turn up they will start appearing in the output almost like magic !

I want to thank everyone who is using this script and those who have left a comment, even if its just to say how much you like it !

I especially want to thank Raphaël SCHITZ (http://www.hypervisor.fr/) for all his contributions, he has added some great features to this version and helped me take it to a new level.

The previous version already reported on these areas: Continue reading →

Virtu-Al VESI & PowerGUI PowerPack

I have been teasing people on twitter for a week or so now and have just uploaded my PowerPack to the PowerGUI site, you can download it here

image

As you can see from the screen shot on the left, this is a first attempt at providing most of my scripts in one PowerPack and adding to the already great management that VESI and PowerGUI give you.

So what do I need to do to install this ?

  1. Install PowerShell V1 or V2 (if you do not already have these installed) V2 Recommended
  2. Install PowerCLI
  3. Install VESI or PowerGUI (VESI Recommended for Virtualization management)
  4. If you have PowerGUI installed you will need to add the  ‘VMware Infrastructure Management’ PowerPack which can be downloaded from here.
  5. Click the download button at the top of this post to download my latest PowerPack, and rate the PowerPack while you are there if you like !
  6. Import the PowerPack into VESI or PowerGUI

From then on you will see both the VMware set of icons and the Virtu-Al icons, you will need to connect to a VI server or number of hosts using the ‘Managed Hosts’ section of the VMware PowerPack, once connected all icons (nodes) become active in the Virtu-Al.net powerpack, simply click on one to see the results.

If you want anything added or find something that doesn’t quite work, firstly make sure you have the latest version of the PowerPack by following this post, if it still doesn’t work please let me know, I am aware of a few bugs and have yet to put any actions in there but please, use it and give me your feedback !

I hope you find this useful !

PowerCLI: vSphere License Export

Seeing Luc’s recent blog post where he explains how to add a vCenter License using PowerCLI, I thought I would stick with the licensing theme and show you how to export your vSphere License keys and details to a csv file enabling you to keep them backed up in a safe place.

This script will only work with vSphere as in vSphere the license server was removed and licensing became a great deal easier, if you want the v3 version you can grab it from my previous post here.

The output can be seen below:

image

Script:

$filename="C:\LicenseInformation.csv"
$ServiceInstance=Get-View ServiceInstance
$LicenseMan=Get-View $ServiceInstance.Content.LicenseManager
$vSphereLicInfo= @()
Foreach ($Licensein$LicenseMan.Licenses){
	$Details="" |Select Name, Key, Total, Used,Information
	$Details.Name=$License.Name
	$Details.Key=$License.LicenseKey
	$Details.Total=$License.Total
	$Details.Used=$License.Used
	$Details.Information=$License.Labels |Select-expandValue
	$vSphereLicInfo+=$Details
}
$vSphereLicInfo |Select Name, Key, Total, Used,Information | Export-Csv -NoTypeInformation $filename

I have included this in my new VESI PowerPack, the version in the PowerPack will automatically work out if your VI is V3 or V4 and show the appropriate information.

image

PowerCLI: Listing Cluster Primary HA Nodes

Following my recent post on Slot Sizes and pointing to Duncan’s great HA Deepdive article I came across a great script today on Hypervisor.fr, he has been creating some great PowerCLI scripts recently and also sent me some fantastic additions to my Daily Report, all of which will be added in the next version which is due out any day now.

Just to set the background I will steel a little of Duncan’s post but please make sure you read his full article and then re-read it until it is ingrained in your brain, this guy knows his stuff.  Duncan’s post reads…

A VMware HA Cluster consists of nodes, primary and secondary nodes. Primary nodes hold cluster settings and all “node states” which are synchronized between primaries. Node states hold for instance resource usage information. In case that vCenter is not available the primary nodes will have a rough estimate of the resource occupation and can take this into account when a fail-over needs to occur. Secondary nodes send their state info to the primary nodes.

Nodes send a heartbeat to each other, which is the mechanism to detect possible outages. Primary nodes send heartbeats to primary nodes only. Secondary nodes send their heartbeats to primary nodes only. Nodes send out these heartbeats every second by default. However this is a changeable value: das.failuredetectioninterval. (Advanced Settings on your HA-Cluster)

The first 5 hosts that join the VMware HA cluster are automatically selected as primary nodes.  All the others are automatically selected as secondary nodes. When you do a reconfigure for HA the primary nodes and secondary nodes are selected again, this is at random. The vCenter client does not show which host is a primary and which is not.

A question was raised on the PowerCLI communities before the days of vSphere asking if you could get the information with regards to which of the hosts were primary for each cluster, a suggestion was made by The PowerCLI master himself LucD to grab the information via a putty session and then present it back onto PowerCLI to use the data.

Now, with vSphere and the updated SDK it would seam that this information is available, so I have modified the script found on Hypervisor.fr to list each cluster and the primary nodes within these cluster as seen in the example below:

image

This can be achieved with a simple (well kinda) script which will check that the cluster has HA enabled and that the vCenter server is Version 4 (vSphere) and then present the results for each cluster:

If ((Get-View ServiceInstance).Content.About.Version-ge “4.0.0“){
Get-View -ViewType ClusterComputeResource |Where {$_.Configuration.DasConfig.Enabled-eq $true} | Select Name,  @{N=“PrimaryHosts“;E={[string]::join(‘ & ‘,(($_.RetrieveDasAdvancedRuntimeInfo()).DasHostInfo.PrimaryHosts))}}
}
Else{
Write “Sorry this is only available to a V4 vCenter Host“
}

Or if the perl toolkit is your cuppa tea then check out this version from William Lam (Perl Ninja)

I have also added this to a VESI PowerPack which I am in the middle of creating and will publish soon, as you can see from the below:

image

PowerCLI: Mass VM Portgroup Change

I was asked in my Script List if it was possible to change Multiple VMs to attach to a new PortGroup, this task is easy enough so long as you remember that every VM can have up to 4 virtual nics in VI3 and up to 10 in vSphere.

So to change all virtual machines we would do the following:

$OldNetwork = "PG1 192.168.0"
$NewNetwork = "PG2 10.1.1"

Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -eq $OldNetwork } |Set-NetworkAdapter -NetworkName $NewNetwork -Confirm:$false

Or to change all of the VMs for a particular cluster we could use:

$Cluster = "Non-Production"
$OldNetwork = "PG1 192.168.0"
$NewNetwork = "PG2 10.1.1"

Get-Cluster $Cluster |Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -eq $OldNetwork } |Set-NetworkAdapter -NetworkName $NewNetwork -Confirm:$false

Note: By default the Set-NetworkAdapter cmdlet would prompt you for each change it was going to make, this is overwritten by using the –Confirm:$false parameter.

Continue reading →