My notes and ramblings, normally about automation

last update:

Documentation is a good thing. No matter how big or small. One of the easiest methods of documentation is to use the built in annotation section for «Notes». What I’ve come up with is a fairly basic script to go through all the VM objects that do not contain notes and allow the user to insert notes on a line by line basis. Here’s an example: Here’s the script to accomplish it:

Found myself in the position of having to add some permissions to an existing file share… Unfortunately none of these systems were 2012R2, whom can take advantage of the SMBShare cmdlets, so this ended up being a bigger task than I would’ve thought. I found tons of help and posts on creating shares, but found a surprising lack of information on a task of this nature which I would’ve thought fairly basic.

Ran into an issue lately where I found a host had lost its storage. For whatever reason HA didn’t kick in to bring all the VMs back to life and there was a need to recreate ~75 VMs whom were in an unknown and/or orphaned state. It looked a bit like this: PowerCLI to the rescue! Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.

Ever had issues with a host randomly disconnecting? vMotions randomly failing? iSCSI paths dropping? If so, there’s a chance you’re having issues with a duplicate IP on one of your VMkernel ports. There’s no real way to display such information through the GUI, so I crafted a quick PowerCLI one-liner to accomplish this task: Get-VMHost -ErrorAction SilentlyContinue | Get-VMHostNetworkAdapter -VMKernel | select VMHost,DeviceName,IP | Group-Object IP | where {$_.Count -gt 1} | %{$_.

Unfortunately, I don’t make use of the Get-View .NET cmdlet as often as I should. It’s a little more complicated than the rest of the PowerCLI cmdlets and a little harder to memorize but the speed is well worth the time and effort. Following up on that, this post is more for selfish reasons since I can never remember the proper ViewTypes. If you put in the wrong one the proper names all pop up but limiting the amount of red on my powershell screens is always a bonus.

HP has released their Scripting Tools for Windows PowerShell: After taking a while to figure out where to download it (HP Download Link), the rest was easy. Once downloaded, just unzip the file wherever you like (note: it isn’t unzipping into an install directory) and then run the included executable. Now open up a PowerShell session and you’re good to go… First thing I did, try and figure out what commands are now available by doing the following command to be greeted by 112 new cmdlets:

As daylight savings time is almost upon us, there are always questions revolving around what hosts use what NTP sources for time synchronization. To address this issue, I created a script to go through and remove the current NTP sources, add the desired NTP sources and then restart the NTP service on all of the hosts in the environment. However, to be safe, the preference was that it wasn’t done all at the same time.

It’s everyone’s favorite time of year, daylight savings time. If your NTP solution is solid, there’s no worries and you’ve never had to think twice about it. If you’re like everyone else, you at least want to run a couple scripts to verify and validate everything is looking good. A little bit of background, the environment I was running this report on had 100+ hosts. An easy one-liner: Get-VMHost | sort Name | select Name,@{Name="Current VMHost Time";Expression={(Get-View $_.

Ran out of ports on a Standard vSwitch and could not reboot the host. Sounds like a good time to implement a Distributed vSwitch and copy the PortGroups over. When you run the script, it will ask for the desired ESXi host name, desired Standard vSwitch name, and the desired Distributed vSwitch name so you don’t have to modify the code. #Take port groups from a specified vSwitch on a specified host and create all the same port groups on a specified Distributed vSwitch $InputHost = Read-Host "Host Name" $InputvSwitch = Read-Host "vSwitch Name" $InputDvS = Read-Host "Distributed vSwitch Name" $vmhost = Get-VMHost $InputHost $vss = Get-VirtualSwitch -Name $InputvSwitch $vssNumPorts = $vss.

After having some bad luck with rescanning HBAs for entire clusters or datacenters all at the same time (Cliff’s Notes: the LUNs ended up looking like array based snapshots and therefore unusable), it was decided that any rescans should be done on an individual host basis. Below is the script I created to achieve this goal. When you run the script, it will ask for the Cluster name so you don’t have to modify the code.

After someone deployed a bunch of VMs, we let them know about the Resource Pool they were supposed to be deployed to. Oops. To correct this, and to avoid a couple hours of dragging and dropping VMs into a resource pool, I was able to create a script that detects if a VM is outside of a Resource Pool and then move it to the specified Resource Pool. When you run the script, it will ask for the Cluster name and the Resource Pool name so you don’t have to modify the code.

So I finally bit the bullet and bought a NAS for my home lab. Ended up with a Synology DS411 due to some good timing from a NewEgg sale. I went with Synology for two reasons: I could supply my own disks (I don’t want the «Green» drives that came with most other NAS units) I always hear REALLY good things about them, they’re always highly recommended. I happened to already have a set of 4 Hitachi Deskstars sitting around so I tossed them in and started running some tests with IOMeter.

Ever received a Security Warning while logging into either you ESX/i host and/or vCenter? That’s due to the SSL certificate being untrusted with your machine. You can always click the «Ignore» button or check the «Install this certificate…» box and then «Ignore» and move on, however you can improve the security by replacing the certificates with certificates signed by a commercial certificate authority (CA). To generate an RSA Key and certificate signing request (CSR), we’ll start by downloading the OpenSSL-Light application on the system you’ll be installing or have already installed a VMware application.

I’ve been playing in the development hosts quite a bit lately which occasionally leave me having to reset the system back to defaults and it’s no fun to go back through and setup Multipathing for 4 connections everytime. So why not setup a PowerCLI script to do it for me! Let me forewarn, I’m an intermediate at best and still getting used to PowerShell and PowerCLI. So far so good though.