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

Here’s another one for you to explore:

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

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



Tagged with:

10 Responses to Virtual Center Server Settings revealed by Powershell (2)

  1. Alan Renouf says:

    Now that is useful, I was wondering how to find out information about the license server, great post.

  2. 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”:

    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

    Any help appreciated, Forbes.

  3. admin says:

    @Forbes Guthrie
    Hi Forbes,
    Just leave $ManagedObjectType = “HostSystem”
    This variable is only used to define to which object the custom field should be attached.

  4. @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]

    # 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
    Disconnect-VIServer -Confirm:$False

    Many thanks, Forbes.

  5. admin says:

    @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.

  6. That’s great, thanks for your effort.

  7. […] have showed you before how to access the License Manager with the Powershell VMware VI Toolkit. But the properties of the […]

  8. Fantastic, thank you Hugo. I’ll let you know how it goes.

Leave a Reply