2011-05-27

Simple VM inventory using PowerCLI

I needed a script that did a simple inventory of production VMs in a vSphere cluster. The output includes the VM name, its IP addresses (only if VMware Tools are installed), its network names, all .vmdk's and the notes field.

Here is the script:

# We go through all VMs that have a 'Production'-notes entry
$AllPrdVMs = Get-VM | Where {$_.Notes -like "Prod*"} | Sort Name
Foreach ($SingleVM in $AllPrdVMs)
{
$VMName    = $SingleVM.Name
# The following two lines enforce the use of an array.
$VMNetwork = @($SingleVM | Get-NetworkAdapter)
$VMHDDs    = @($SingleVM | Get-HardDisk)
# The following line only works if VMware Tools are installed
$VMIP      = $SingleVM.Guest.IPAddress
$VMNote    = $SingleVM.Notes
Write-Host ($VMName) -ForegroundColor Red -NoNewLine
Write-Host (" " + $VMIP) -ForegroundColor Yellow
# Here we loop through the arrays - even if there is only one member
For ($Count = 1; $Count -le $VMNetwork.Length; $Count++)
{
Write-Host $VMNetwork[$Count - 1].NetworkName
}
For ($Count = 1; $Count -le $VMHDDs.Length; $Count++)
{
Write-Host $VMHDDs[$Count - 1].Filename -ForegroundColor Blue
}
Write-Host ($VMNote)
Write-Host
}


PS: First post with syntax-highlighting ;-)

2011-05-26

Remote Session Disconnected

Your remote session may be disconnected with the message: "The remote session was disconnected because the terminal server client access license stored on this computer has been modified"
At this point you should remove the saved terminal server licenses from the client registry. Delete the following key from the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSLicensing
The key will be created the next time you log on to the Terminal Server.
Additional information can be found: http://support.microsoft.com/kb/315262

Sessions for Microsoft TechEd 2011 North America are online

Many different sessions are online and downloadable. Security, management, background information etc.
Here is the link to the site:
http://channel9.msdn.com/Events/TechEd/NorthAmerica/2011

Terminal Server Temp Profile

Sometimes users complain because they makes changes in their Windows Terminal Server Session and the settings are lost after they logged out.
The problem is that the User Profile is not saved on a Windows Terminal Server.
You can solve this problem by deleting an entry in the registry:
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
Under this hive you can find a folder for every user. Find the folder with a .bak at the end and delete it.


2011-05-23

Failed HP VCA installation

Just had it today. An HP Version Control Agent (version 6.3.0.870, x64) failed to install. Basically the cp013991.exe crashed under Windows Server 2008 R2. But no real error message.

What helped? Ran the cp013991.exe and selected Extract...
Then in an elevated command prompt I ran the vcagent.msi
Finally got an error message: A previous version was still installed. :-) (A previous update from the HP Version Control Repository had failed, leaving the older version of VCA in an undefined state.)

So I uninstalled the previous version manually and could re-install the current version.

Check for expired passwords

How can I check if an Active Directory password is already expired? It is useful for one own password but also to check if password expiration is the reason why a certain user cannot login.

I found this PowerShell script in one of my PowerShell profiles (PS: I did not create it. I think i got it from here http://blogs.msdn.com/b/adpowershell/archive/2010/02/26/find-out-when-your-password-expires.aspx).

Here is the script:

new-alias -name Get-PWExp -value "Get-XADUserPasswordExpirationDate"


function Get-XADUserPasswordExpirationDate() {
Param ([Parameter(Mandatory=$true,  Position=0,  ValueFromPipeline=$true, HelpMessage="Identity of the Account")]
[Object] $accountIdentity)
PROCESS {
$accountObj = Get-ADUser $accountIdentity -properties PasswordExpired, PasswordNeverExpires, PasswordLastSet
if ($accountObj.PasswordExpired) {
echo ("Password of account: " + $accountObj.Name + " already expired!")
} else { 
if ($accountObj.PasswordNeverExpires) {
echo ("Password of account: " + $accountObj.Name + " is set to never expires!")
} else {
$passwordSetDate = $accountObj.PasswordLastSet
if ($passwordSetDate -eq $null) {
echo ("Password of account: " + $accountObj.Name + " has never been set!")
}  else {
$maxPasswordAgeTimeSpan = $null
$dfl = (get-addomain).DomainMode
if ($dfl -ge 3) { 
## Greater than Windows2008 domain functional level
$accountFGPP = Get-ADUserResultantPasswordPolicy $accountObj
if ($accountFGPP -ne $null) {
$maxPasswordAgeTimeSpan = $accountFGPP.MaxPasswordAge
} else {
$maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge
}
} else {
$maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge
}
if ($maxPasswordAgeTimeSpan -eq $null -or $maxPasswordAgeTimeSpan.TotalMilliseconds -eq 0) {
echo ("MaxPasswordAge is not set for the domain or is set to zero!")
} else {
echo ("Password of account: " + $accountObj.Name + " expires on: " + ($passwordSetDate + $maxPasswordAgeTimeSpan))
}
}
}
}
}
}

2011-05-21

Nicely designed themes for Ubuntu (with Gnome 2)

I really like the Bisigi themes for Ubuntu with Gnome 2 (no support for Unity planned). They beautifully designed and also un-cluttered.

Here is the website:

2011-05-20

Firefox tweaks to improve Google Reader experience

These are settings I usually set in every Firefox instance I use.
In about:config make these settings:

dom.popup_maximum = 20000
browser.tabs.loadDivertedInBackground = True

Find VM snapshots

VM snapshots can eat up a lot of storage space. Sometimes snapshots get created automatically by backup software but are not automatically deleted.

A little PowerCLI script to find virtual machine snapshots in a vSphere cluster.

Get-VM | Get-Snapshot | Select VM,Name,SizeMB,Created | Sort SizeMB -Desc

PS: The size is interesting, also the age of the snapshot, the name sometimes makes it clear if it was a manually or automatically created snapshot.

Find duplicate MAC addresses

In the physical world duplicate MAC addresses rarely happened. In the virtual world this can happen quite easily. How to find those?

A little PowerCLI script that looks through all VMs in a vSphere cluster / vSphere host and sorts entries by MAC addresses:

Connect-VIServer [server name]
Get-VM | Get-NetworkAdapter | select MacAddress,Parent,NetworkName | sort MacAddress


Update: see also 2nd entry: http://adminthoughtcollection.blogspot.com/2011/08/find-duplicate-mac-addresses-2.html



First post

The idea behind this blog is to collect ideas and solutions in connection with real life admin work. To have it all in one place will hopefully help me to find things again ;-)