After I wrote the licensing server post a couple of days back one of my colleagues(Thanks Horst!) was so kind to email me the following script. What it basically does is check every server for the availability of the license source. Of course it can be improved by adding for instance a check to see if the license service is running on the license server and for instance email the results if there’s an error… [Read more…] about Check if your license server is still running…
powershell
Speed up your powershell scripts
On the VI Toolkit blog there’s a great article for people like me. They explain how to speed up your scripts. I’m no powershell guru, and these kind of articles are more than welcome to boost my scripting skills.
In short, it comes down to these three tips:
- Try to load as many objects as possible into arrays beforehand. Once you’ve got them loaded you can use them as arguments to multiple calls without having to resort to potentially expensive lookups every time.
- Just like in sample 1 above, when you’ve loaded objects, use the objects directly rather than using their names. This is usually not hard as our cmdlets are designed to take object first-and-foremost, and names are supported just as a convenience.
- If you absolutely need to load a single VM object by name, load it using the Get-VMFast function below. While this approach can certainly help, it’s not nearly as good as using the other two techniques mentioned above.
Head over to the VI Toolkit blog and start reading.
Powershell and importing .CSV files
I’ve been playing around with powershell yesterday. We needed to create over 100 VM’s and there’s no point in doing that all by hand. The customer provided us with a .csv file that contained specific info on these VM’s. It took me a while to figure out how to read the info.csv file and how to actually use it. But as always it’s actually fairly simple and that’s why I decided to write it down:
Before we even start, the CSV should be formatted as follows:
vmname,cluster
VM001,HA-DRS-Yellow-Bricks
Read the complete csv file into a variable:
$csv_info = Import-Csv c:\scripts\info.csv
For every line in the csv variable do something:
foreach ($line in $csv_info) {
write-host " This is virtual machine $($line.vmname) on cluster $($line.cluster)"
}
This line would print something like this:
This is virtual machine VM001 on cluster HA-DRS-Yellow-Bricks
As you noticed in the example above we used $line.vmname to get the name of the VM printed and $line.cluster for the cluster name, cool huh! BTW, Alan’s quick reference guide really helped me out!
Set Disk.UseDeviceReset with powershell
Last week the well known powershell guru Alan Renouf helped me out with a script for enabling virtualized MMU. This week I needed to set Disk.UseDeviceReset to “0” on at least 60 hosts. (Check the link for more info on why!) No point in doing it all by hand when the VI Toolkit can help you out and set this parameter for the entire environment with just one line:
Get-VMHost | Set-VMHostAdvancedConfiguration -Name Disk.UseDeviceReset -Value 0
I’m really starting to get excited about the VI Toolkit, thanks to guys like Alan and of course the VMworld VI Toolkit Lab I did a couple of weeks ago. With the quick reference guide that Alan created it’s very simple to come up with one-liners like the one above.
DEPRECATED See this article for more info.
Balancing LUN paths with powershell
Just noticed this pingback. The topic title “Balancing LUN paths on your ESX hosts with powershell” sounded promising so I headed over. Justin Emerson is the owner of the blog and he wrote a short but effective script that changes the active paths on your active/active SAN(FIXED).
After watching this video that was posted by the VI Toolkit team, I immediately thought of this script that was posted quite a while back on Yellow Bricks. I decided to try to recreate this script in PowerShell, and while I was at it expand it so it would modify all nodes in a cluster at once. As such I wrote the following script. Please feel free to give feedback or make modifications! You can download it from my Sky Drive or check it out here.
Head over to Justin’s site, pick up the script and give it a try… and most importantly give Justin feedback on the results and what could be improved!