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«

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

  3. admin says:

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

  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]
    $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.

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

  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