In order to access my lab environment I have configured a VMware View Infrastructure. I use two connection brokers. One for internal clients, and one for external clients, which goes via a View Security Server originally on 4.6, now 5.0 with PCoIP enabled. This would be completely normal and easy to operate if I had a static IP address. But alas I don’t.
In order to work around this I borrowed a script from a great blog and modified it for my purposes. Below is the script I use to update the external IP address / URL of my View Security Server every time my IP address changes. The great thing about this script is that it works with multiple View connection or security servers in the environment. Enjoy!
I got the original script at Gabes Virtual World – Enabling VMware View 4.6 PCoIP with dynamic IP address and then modified it to work with multiple View connection servers. The key section that I modified below is in red. Before this modification if you called the script and had multiple connection brokers in your environment it would fail. A big thanks to Gabe for originally authoring the script. Without it access to my lab would be very difficult indeed. This may help smaller companies who don’t want to go to the expense of having static ip address space access their remote View environments. The PowerShell script requires the View snap-in’s and should be run from the internal connection broker, not the security server. Make sure you have the correct firewall rules in place for the ports that View 4.6 and above requires. The script works with View 4.6 and above, so includes View 5.0, which I’m now using in my lab.
Add-PSSnapin VMware.VimAutomation.Core
Add-PSSnapin VMware.View.Broker
# Name of the Security Server
$SecurityServer = “VIEWSECSRV”
# For logging creating a timestamp
$TimeStamp = Get-Date -format yyyy-MM-dd-H-mm
# Filling $CheckedIP with the external IP address, using whatismyip.com service
$wc = New-Object net.WebClient
$CheckedIP = $wc.downloadstring(“http://automation.whatismyip.com/n09230945.asp”) # This can be any simple ip display page
# Now check the current ExternalPCoIPURL entry
$CurrentSettings = Get-ConnectionBroker
ForEach ($ConnectionBroker in $CurrentSettings){
if ($ConnectionBroker.broker_id -eq $SecurityServer) {
$CurrentIP = $ConnectionBroker.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 “VIEWSECSRV” -externalPCoIPURL $CheckedIP
# Check if it was succesful
$NewSettings = Get-ConnectionBroker
$row = $TimeStamp + “,” + $CheckedIP + “,” + $CurrentIP + “,” + $NewSettings.externalPCoIPURL
}
$row | Out-File -FilePath “C:\scripts\check-ip.log” -Append
The above script first appeared on Gabe’s Virtual World at http://www.gabesvirtualworld.com prior to my modifications to the script.
This Post By Michael Webster +. Copyright © 2012 – IT Solutions 2000 Ltd and Michael Webster +. All rights reserved. Not to be reproduced for commercial purposes without written permission.