All posts by admin

Poor Man’s Virtual Machine Backup with PowerCLI

Are you still performing old-school in-guest VM backups with a backup agent? Not ready to buy a backup product that does complete VM backups through the vStorage APIs? Then you will need to rebuild all your VM’s with the original configuration before you can start restoring your data.

As always: PowerCLI to the rescue! This script will connect to vCenter Servers on your primary site and secondary (recovery) site. Continue reading

»crosslinked«

Calculate vSphere 5 Licenses with Powershell (UPDATED)

VMware has announced the next generation of vSphere yesterday. Besides lots of new features, vSphere 5 also comes with a new licensing structure. For every licensed physical CPU, you get a certain amount of vRAM, which you will be able to allocate to virtual machine. Only the running VM’s will count towards your license limit.
Curious how the vSphere 5 licensing model will impact your license cost? Want to know how many vSphere 5 liceses you will need? The following script calculates exactly how many licenses you need for the different editions and how much overhead you will have left.

UPDATE 04-AUG-2011: vmware has increased vRAM entitlements for all editions of vSphere 5! I have updated the script (shown below and the attached script). The screenshot is still the old one. Please read the new Licensing PDF here for all the details.

NOTE: Please note that I add up all your pCpu’s, ignoring current license types. I also add up all your current vRAM usage (RAM assigned to powered on VM’s). I then show you different scenarios if you purchase license type x for ALL your pCpu’s. If your environment consists of a mix of vSphere editions, check out Alan Renouf’s script to analyse your environment.


Continue reading

Remove vmware memory limits with Powershell

Using Memory Limits in vmware vSphere can cause severe performance issues. The guest operating system assumes it can use all of the allocated memory, but vSphere will make sure the vm cannot use more than the memory limit. It does this by inflating a memory balloon using the balloon driver included with the vmware tools. The performance chart in the vSphere Client will show the virtual machine is ballooning. I never recommend using memory limits in vmware.
The following script will remove all memory limits in your vSphere infrastructure, preventing the problems described above. Continue reading

Convert Scripts to Module

I used to have all my common functions stored as separate scripts in a single folder. I’d load these through a few lines of code in my profile, looping through the script files and dot-sourcing them. Powershell v2.0 has a new feature called Modules. So how do you convert a bunch of scripts (containing functions) into a single module you can load or unload whenever you feel you might need those functions?

Here’s how:

# Convert function scripts to Module
 
#Variables
$myModuleName = "myModule123"
$inputFolder = 'D:\scripts\Functions'
$outputFolder = "$PSHOME\Modules\$myModuleName"
 
#Create the module directory
$null = New-Item $outputFolder -ItemType directory
 
#Create the module with a nice oneliner
Get-ChildItem $inputFolder -Filter "*.ps1" | Get-Content | Out-File "$outputFolder\$myModuleName.psm1" -Append
 
#Import the module
Import-Module $myModuleName
 
#Show functions loaded from the module
Get-Command -Module $myModuleName

Set vApp Guest Shutdown

Annoyed by the default setting for VM’s inside a vApp? I was, because when you power down the vApp, the VM’s are powered down instead of being shutdown cleanly. It can be a tedious task to check and correct this setting for all your vApps. This little script solves that problem for you. Enjoy!

$VC = Connect-VIServer "MyvCenter.local"
 
ForEach ($Vapp in Get-VApp)
{	
	$VAppView = $VApp | Get-View
	ForEach ($Entity in $VAppView.VAppConfig.EntityConfig)
	{
		If ($Entity.StopAction -ne "guestShutdown")
		{
		$VAppConfigSpec = New-Object VMware.Vim.VAppConfigSpec
		$EntityConfig = New-Object VMware.Vim.VAppEntityConfigInfo
			$EntityConfig.Key = (Get-View $Entity.Key).MoRef
			$EntityConfig.StopAction = "guestShutdown"
		$VAppConfigSpec.EntityConfig = $EntityConfig
 
		$VAppView.UpdateVAppConfig($VAppConfigSpec)
		}
	}
}
 
Disconnect-VIServer -Confirm:$false

Download script: Set-VAppGuestShutdown (rename to .ps1)

Find LUN ID’s in VMware with Powershell

Determining the LUN ID for a specific LUN in your VMware Infrastructure used to be simple. It was listed as one of the properties of the datastore you selected in the VI Client. Nowadays, more often than not, I dont see the LUN ID in the vSphere Client. Instead, I see some sort of identifier like “EMC Fibre Channel Disk (sym.12673548127)”.
Even more unfortunate is the fact that all my scripts show the same identifier, where they used to show the LUN ID. So I decided to create a script that can translate the identifier (sometimes referred to as Canonical Name) back to a LUN ID.
By the way: in the vSphere Client, you can still find the LUN ID by opening the datastore’s properties window and clicking Manage Paths. Or you could write down the canonical name, switch to the devices view and look up the device there. That is essentially what my script does for you.
Here we go:
Continue reading

Fix DCOM Event 10005 with Powershell

Do you get these events in your system log?

The service cannot be started, either because it is disabled or because it has no enabled devices associated with it. attempting to start the service ntmssvc with arguments “-Service” in order to run the server:
{D61A27C6-8F53-11D0-BFA0-00A024151983}

Symantec explains this is caused by disabling the Removable Storage Manager and provides a solution.

Removing those registry keys on a bunch of servers manually is a pain. Modifying DCOM settings even more so. So I explored fixing this with Powershell.

Continue reading