View 5.0: View PowerCLI

Recently from my previous post, I have upgraded my home lab to VMware View 5.0.

Everytime seems working.  For those who ain't aware, my ISP issue dynamic IP.  In such, I created a domain name from dyndns.org.

As to match my external IP to my View Security Server with my external dns name, I would need to use a script which was found from the source below.

I did some modification to suit my environment and corrected some mistake.  Below is my script.


However in View 5.0, it has to be launch using the View PowerCLI and Add-PSSnapin VMware.View.Broker is no long working anymore. (which it did in View 4.6).  This was documented in VMware KB 1034652.

A quick check with the View PowerCLI properties from Start Menu, I realize it is calling a powershell script from C:\Program Files\VMware\VMware View\Server\extras\PowerShell\add-snapin.ps1 so in such I added the change in my script as you can see.  This was documented

Now my script is running fine again and my log file is updated correctly.


Add-PSSnapin VMware.VimAutomation.Core
#Add-PSSnapin VMware.View.Broker
& 'C:\Program Files\VMware\VMware View\Server\extras\PowerShell\add-snapin.ps1'
# Name of the Security Server
$SecurityServer = "sg-ss"

# For logging creating a timestamp
$TimeStamp = Get-Date -format yyyy-MM-dd-H-mm

# Filling $CheckedIP with the external IP address, using whatismyip.com checkip.dyndns.com service
$wc = New-Object net.WebClient
$CheckedIP = $wc.downloadstring("http://www.whatismyip.org/")

$CheckedIP = $wc.downloadstring("http://checkip.dyndns.com") -replace "[^\d\.]"

# Now check the current ExternalPCoIPURL entry [0] is connection server [1] is securityserver
$CurrentSettings = Get-ConnectionBroker
$CurrentIP = $CurrentSettings[1].externalPCoIPURL


# Check if $CurrentIP starts with the IP address from $CheckedIP
# Used StartsWith because $CurrentIP has port address at the end
$Result = $CurrentIP.StartsWith($CheckedIP)

# Are IP address the same?
If ($Result)
{
     # Yes, both IP addresses are the same, do nothing, only write a log entry
     $row = $TimeStamp + "," + $CheckedIP + "," + $CurrentIP + ",nochange"
}
else
{
    # External IP is not equal to IP set in externalPCoIPURL
    # Changing the externalPCoIPURL
    Update-ConnectionBroker -broker_id $SecurityServer -externalPCoIPURL $CheckedIP

    # Check if it was succesful
    $NewSettings = Get-ConnectionBroker
    $row = $TimeStamp + "," + $CheckedIP + "," + $CurrentIP + "," + $NewSettings.externalPCoIPURL + ",changed"
}
$row | Out-File -FilePath "c:\check-ip.log" -Append




Reference


Update 24th Jan 2013
www.whatismyip.com now have more than just text and the container will store more than just IP which breaks the code and not updating the security server.  Have amended the code above with http://checkip.dyndns.org.  Tested and running fine now on View 5.1.2.

Comments

Popular posts from this blog

Why VMware or Why Not after Broadcom?

VMware by Broadcom, A New Chapter Forward

VMware vExpert 2024 Application is Now Open!