Virtual Center Server Settings revealed by Powershell (2)

VI Toolkit Product Manager Carter Shanklin pointed out in the VMware Communities that the script I posted yesterday can be significantly shortened. They have intrduced the shortcut:

Get-View ServiceInstance

So the script I posted yesterday can be reduced to:

$SI = Get-View ServiceInstance
$LicMan = Get-View $SI.Content.LicenseManager
$LicMan.Source.LicenseServer

Here’s another one for you to explore:

$OM = Get-View $SI.Content.Setting
$OM.Setting

…et voilĂ : SNMP and SMTP settings at your fingertips.

Enjoy!

»crosslinked«

10 thoughts on “Virtual Center Server Settings revealed by Powershell (2)”

  1. Hi Hugo,
    love the PowerShell scripts so far, keep them coming! I would like to add a License Server query to your “Custom Fields” script, so that I can show if each host is correctly connected to our License Server.

    I have been looking at the “LicenseState”:
    http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.LicenseManager.LicenseState.html

    Is this even possible with this different Managed Object Type? If so where am I going wrong (here’s the relevant code)?

    $ManagedObjectType = “LicenseManager”

    ForEach ($VMHostView in $VMHostViews)
    {
    $License = $VMHostView.Content.LicenseManagerState
    # Compare value to current value
    If ($License -ne ($VMView.CustomValue | ?{$_.Key -eq $myCustomField.Key}).Value)
    {
    # Set Custom Value
    $VMHostView.setCustomValue($CustomFieldName,$License)
    }
    }

    Any help appreciated, Forbes.

  2. @admin

    Hi Hugo,

    I’ve tried it with both, but no luck. I can run this against VC, but all it gives is the license server of VC itself. I would like to run this (or something similar) against each host (I’m have an ongoing license issue with several hosts which I need to monitor). Can you spot anything wrong with this:

    . “C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts\Initialize-VIToolkitEnvironment.ps1″

    # Variables
    $VCServerName = “VCSERVER”
    $CustomFieldName = “LicenseState”
    $ManagedObjectType = “HostSystem”

    # Script
    $VC = Connect-VIServer $VCServerName
    $SI = Get-View ServiceInstance
    $CFM = Get-View $SI.Content.CustomFieldsManager

    $myCustomField = $CFM.Field | Where {$_.Name -eq $CustomFieldName}
    If (!$myCustomField)
    {
    # Create Custom Field
    $FieldCopy = $CFM.Field[0]
    $CFM.AddCustomFieldDef($CustomFieldName,$ManagedObjectType,$FieldCopy.FieldDefPrivileges,$FieldCopy.FieldInstancePrivileges)
    }

    # Fill Custom Fields
    $VMHosts = Get-VMHost
    $VMHostViews = $VMHosts | Get-View
    ForEach ($VMHostView in $VMHostViews)
    {
    $LicenseState = $VMHostView.Content.LicenseManagerState
    # Compare value to current value
    If ($LicenseState -ne ($VMView.CustomValue | ?{$_.Key -eq $myCustomField.Key}).Value)
    {
    # Set Custom Value
    $VMHostView.setCustomValue($CustomFieldName,$LicenseState)
    }
    }
    Disconnect-VIServer -Confirm:$False

    Many thanks, Forbes.

  3. @Forbes Guthrie
    Then the issue us in this line:
    $LicenseState = $VMHostView.Content.LicenseManagerState
    This apparently retrieves the VC Licence State, not the ESX Server Licence State.
    I’ll take a look if I can find the proper field.
    Hugo

Leave a Reply