Category Archives: PowerShell

VI Toolkit Competition Winners

I might not have won but at least I get a mug and a T-shirt, check the honorable mentions!

http://blogs.vmware.com/vipowershell/2008/09/announcing-the.html

Have to say I can see why the second place reporting script was in the winning slots but I’m not sure people really want to install that much extra to get a report, I think our reports were aiming at two different audiences.

Well done to the winners, great job.

Also I had a really nice mention on Carter Shanklin’s blog here….

http://blogs.vmware.com/vipowershell/2008/09/and-the-winner.html

If you ask me, thats better than winning (although VMworld would have been nice :))

VI Errors one-liner

A quick one-liner that would be usefull in an email to you each morning via a scheduled task….

For the whole VI….

Get-VIEvent -Type Error | Format-Table CreatedTime, FullFormattedMessage

For a specific cluster…

Get-Cluster “MYCLUSTER” | Get-VIEvent -Type Error | Format-Table CreatedTime, FullFormattedMessage

I might even do a daily health check script which gives you performance stats and errors, complete with email options and instructions on how to setup as a scheduled task, please let me know if this will be usefull.

Find this and other great one-liners here

I dont have time to learn PowerShell…..

Rubbish !

I heard on one of the pod casts about this website so I thought I would blog about it for all of my sysadmin friends who claim they do not have time to learn PowerShell.

The important thing to remember is that if you follow these and start using PowerShell you will be saving time in the future, and believe me you will be saving alot of time.

The important thing to remember about PowerShell is that it isn’t only there for the scripts its also there for the simple commands that you don’t need to write massive scripts for.

For example if you need information about how much memory each server has and what domain it is in and what make the server is and you have the names in a text file then this simple one-liner can get that for you….

Get-Content C:\Servers.txt |Foreach-object {Get-WmiObject -class Win32_ComputerSystem –computername $_} | Format-Table Name, Domain, Model, TotalPhysicalMemory

Now think about how much time it would take you to rdp to each server and gather this information ?!?

Seriously, get learning…..

Learning Powershell in your lunch break Episode 1 – Getting Organized
Learning Powershell in your lunch break Episode 2 – Writing Scripts and Translating VBScript
Learning Powershell in your lunch break Episode 3 – Discovering objects (COM, WMI & ADSI)
Learning Powershell in your lunch break Episode 4 – Ins and Outs of the Windows Registry
Learning Powershell in your lunch break Episode 5 – Using WMI
Learning Powershell in your lunch break Episode 6 – ADSI Connecting to Domains/Computers and Binding Objects
Learning Powershell in your lunch break Episode 7 – Manage Users

I dare you to go through these and then not use PowerShell !

VI PowerScripter

Hal just pointed me to a new VI Client Plugin that integrates powershell into the VI Console, looks neat…

Download here

comasoft® VI PowerScripter (currently beta 1) is the first and absolutely unique VMware VI Client plug-in for a tight integration of user-defined PowerShell scripts into the object repository of VMware Virtual Infrastructure 3.5.

This plug-in delivers some predefined scripts for common admin tasks and is capable of handling hundreds of custom scripts for direct usage from a dynamically generated context menu within VI Client (for connections to VirtualCenter, ESX 3.5 or ESX 3i).

Thanks to its absolute flexibility, this powerful software is a “must” for professional users looking to administrate the virtual infrastructure in compliance with business-aligned functions in a simple and yet most effective manner.

Features

  • Load any VI PowerShell script through a dynamically created context menu (often no change needed)
  • Use of VM or Host based PowerShell scripts
  • Run Scripts against single or multiple chosen objects (also Cluster, DataCenter)
  • Switch between Debug and silent mode
  • Use local scripts or scripts from network shares
  • Enhance the VI Client or VirtualCenter functionality for your demands
  • PowerShell scripts using the correct VirtualCenter access rights
  • all script activities are logged
  • Usage of predefined scripts provided by icomasoft
  • Support for PowerGUI powerpack files

Free Powershell Book

Learn Microsoft Windows PowerShell one step at a time with practical,
hands-on instruction from Microsoft’s leading scripting trainer, Ed
Wilson.

Work at your own pace and build practical system administration
skills as you learn how to use Windows PowerShell to administer
Microsoft Windows, Microsoft Exchange, and other Microsoft technologies.

You will learn how to write your first Windows PowerShell commands and
scripts to automate setup, deployment, and administration.

Download here

Last minute entry…Its great !

A last minute entry has just come into the VMware PowerShell Comp and its very good….

This script will generate 2 .txt file reports based on your virtual environment.

The first report (report.txt) includes resource utilization across all Clusters including CPU and Memory usage for the cluster as a whole as well as each individual ESX host.
It will also list the VM to Host Ratio for the cluster.

The latter portion of the report includes an overview of total Datastore space allocated to the environment as well as space available and the amount of space used by powered off VMs.

The first report finishes off with a listing of all datastores with details on available space, capacity and % used.The second report is a hotlist (hotlist.txt which includes VM’s that are using, on average, more than 75% of their allocated memory.

It also includes hosts that are using more than 75% of their Memory or CPU.
It continues by listing datastores with less than 10% of their capacity available.
Finally it pulls WARNING messages from each ESX host’s VMKernel log since the beginning of the previous day.

The first report (report.txt) is designed to bring a high level view of the environment for reporting purposes as well as for making decisions on where additional resources may need to be allocated on a cluster level.
It is particularly useful for providing numbers up the chain of command without needing to pore through Virtual Center collecting data.

The second report is useful from a health check standpoint. It automatically identifies vm’s and hosts that are running hot to give an analyst an idea of where they may need to look into problems.

The datastore report is useful for determining ahead of time when additional storage needs to be allocated and where it should be used. Perhaps the most useful part of the report is the ESX logs. It’s a single place for analysts to watch for early signs of issues that may not be apparent when just using Virtual Center.

The script is a perfect item to run at the beginning of the day before heading down the hall to grab a cup of coffee.

Check it out here

Check Active Directory Latency Script

Here is a neat Powershell script that:

  • Finds all Domain Controllers in the Domain (using .NET)
  • Creates a contact object in a specified OU (Default is users container for the Domain)
  • Gets the start Time
  • Loops and Checks each DC for the object.
  • Once all DCs have the object it gets End Time
  • Outputs the results

Basically you can check how long it takes to replicate to each of your sites. Very Usefull !

Bigup Myself !

Im starting to get famous, very slowly my plan to virtualise the world is coming together (as I once said.. Virtualise the world, Virtualise the cheerleader)

My script which exports configuration information from Virtual Center straight into MS Word has now been used by a fair few poeple and it seems to be working, which is good as I couldnt give it the testing I would have liked to.

1. A few people in the forum have been using it and comments are good …..link here

2. I had an email from someone who used it against there system running it over a VPN connection to the VI Server with over 20 ESX servers and over 250 VM’s, the script produced a 1.56 MB which has 50 pages. large scale testing !!!

3. I had a mention in the get-scripting podcast (I havnt sync’d my zune yet but will listen when I get home today), thanks Jonathan.

Rescan all hosts for new storage

More of a note for myself really but others may find this useful, to rescan all the hosts (rather than clicking Rescan in the GUI) you can run the following PowerShell command:

For a Specific Cluster:

get-cluster -name “MY CLUSTER” | get-vmhost | Get-VMHostStorage -RescanAllHBA

All Hosts in VC:

get-vmhost | Get-VMHostStorage -RescanAllHBA