VIProperties in a Module

Judging from the number of hits, the VIProperties page seems to be rather popular.
The number of entries on that page increases nearly on a daily basis.And judging by the list of people who submitted New-VIProperty entries, this particular feature of PowerCLI is in use all over the place.
Recently my co-author of the PowerCLI book, Jonathan Medd, had a brilliant idea.

Why not bundle all the VIProperties in a module ? The user would just have to do an Import-Module, instead of a copy/paste on each of the entries.

So for the 100th post on my blog I decided to bring you the VIProperty module.

Update August 25th 2011: added the use of the PowerCLI 5 Get-VIProperty cmdlet.

Installation

  • Download the

    VIProperty Module (3.2 KiB)

  • Unblock the ZIP file to avoid problems with your PowerShell ExecutionPolicy.

  • Extract the files from the ZIP file. This will create a folder called VIProperty, with 2 files in there.
  • Copy the complete VIProperty folder to one of your Modules folders.
    • You can check which are the Modules folders on your system like this

Usage

In you PowerCLI session you can load the VIProperty module at any time with the Import-Module cmdlet.

Since the VIProperty module doesn’t introduce functions, you can’t use the Get-Command cmdlet to see what is in the VIProperty module. But PowerCLI 5 introduced the Get-VIPropery cmdlet that can help.

When you do

it will return a list like this

To remove the VIProperty module you can do

but this will not remove the New-VIProperty definitions.
To actually remove the New-VIProperty definitions, you can do

Enjoy !

16 Comments

    Steve Rackham

    Hi Guys
    Can you do a VIProperty for the Network Adapter type? For example, finding all E1000s Nics? We can do this separately but would be awesome to see in a single report.
    Thanks

    S.

    dan

    Hi Lucd,

    “Update August 25th 2011 ” ??? Isn’t that too old … Any updates Please share …

    One I am looking for is , get-vm to show me vm’s cluster name …. if you have that will be gr8 !

    thanks

      SR

      I started using LucD’s module a while ago and its great. I’ve even started adding in my own. To show the clustername via the ‘Get-VM’ cmdlet I added the following

      New-VIProperty -ObjectType VirtualMachine -Name VMCluster `
      -Value {param($vm)($vm|Get-Cluster).Name} -Force

      It works fine for me.
      Enjoy

        LucD

        Thanks Stevie, I included your VMCluster on the page and in the ZIP file.

        I’ll have to revive this repository, there’s a ton of new properties I should add.

    CJH

    @LucD

    Ah, that explains it.

    I was hoping that get-viproperty would provide a way to get existing properties…like those of a virtual machine…not just those properties created by new-viproperty. If it doesn’t, the cmdlet is of little use to me.

    Thanks for your speedy responses!

    CJH

    @LucD
    Nothing is returned when I run get-viproperty.

    PowerCLI C:\> get-viproperty
    PowerCLI C:\>

    I’m not using the module, just the cmdlet get-viproperty.

      LucD

      @CJH, if you didn’t define a new property with the New-VIProperty cmdlet, then nothing will be returned by the Get-VIProperty cmdlet.
      Did you try to do the New-VIProperty I gave in my previous reply ?

    CJH

    @LucD

    Yup. In fact I upgraded this morning specifically to use this cmdlet in a script.

    PowerCLI C:\> get-powercliversion
    PowerCLI Version
    —————-
    VMware vSphere PowerCLI 5.0.1 build 581491
    —————
    Snapin Versions
    —————
    VMware AutoDeploy PowerCLI Component 5.0 build 544967
    VMware ImageBuilder PowerCLI Component 5.0 build 544967
    VMware License PowerCLI Component 5.0 build 544881
    VMware vSphere PowerCLI Component 5.0 build 581435

      LucD

      @CJH, that is the latest build.
      What exactly happens when you do the Get-VIProperty ?
      Do you get an error ?
      Or is nothing returned ?
      Perhaps create a small test property with

      New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine -Value {
      param($vm)
      $vm.ExtensionData.Guest.ToolsVersionStatus
      } -Force

      And then do the Get-VIProperty. The new property you just created should show up.
      If it did, then something probably went wrong with the Import-Module.
      Did you follow the instructions to unpack the module ?
      In which folder did you please the module ?
      Is that folder listed when you do

      $env:PSModulePath

    CJH

    For some reason get-viproperty doesn’t work for me. Does anyone else have this issue?

      LucD

      Hi CJH,
      Are you running a recent PowerCLI version ? Do a

      Get-PowerCLIVersion

      That should preferably show a 5.x version.

    andreas brunner

    Hi Luc,

    great work.

    This remindes me to a former discussion we had 🙂
    http://communities.vmware.com/thread/316000?start=15&tstart=0

    regards

    Andreas

    Hal Rottenberg

    Don’t forget to remind people to unblock the zip archive before extracting. This will help prevent confusion in case your execution policy is set to RemoteSigned.

      LucD

      Thanks Hal, I’ve added the “unblock” step.

    Craig Myers

    This just made writing reports so much easier, thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

Buy the Book