Update: Wow my script got a mention on the PowerScripting podcast 🙂 Episode 101 – Matthew Giles from Connect-SMART « PowerScripting Podcast
After doing lots of work with VMware View recently I have decided to try and write a few Powershell scripts to assist with View rollouts / administration. This first small script will update a custom field for each VM with the current logged in user. This helps considerably when your are in the vSphere client with a large amount of VM’s and need to track down the user of a particular VM. Maybe you need to log in to check an issue their having, investigate high CPU usage or just quickly find out which VM is assigned to which users. Obviously this can be done through the View Manager but most people won’t have this open on a daily bases.
The script can either be ran as needed or scheduled to run using Windows Scheduled Tasks, for information on how to do this check out Alan Renouf’s blog post http://www.virtu-al.net/2009/07/10/running-a-powercli-scheduled-task/
As the script uses WMI to get the information regarding the logged in users, you must ensure you run this as user with sufficient privileges over the machines you are querying.
I am using a wild card in the get-vm command to find all my VM’s that contain xp in the name, this can easily be changed to meet the requirements of your View environment.
If no one is logged in when the script runs the custom field is updated with “No One Logged In”
As ever this is a work in progress and I am sure their are numerous ways it could be improved so I look forward to your suggestions and comments.
Example of how it looks in a list
Single VM View
As ever many thanks to Alan Renouf and his blog www.virtu-al.net for the inspiration.
I have mixed success with this script, sometimes I am getting the logged in user returned correctly other time not. Would be interested to head what anyone else’s experiences. It seems the logged in user isn’t always returned from WMI, this seems strange considering I am using a domain admins account.