Author Archives: Alan

About Alan

Alan Renouf has a role of Automation Frameworks Product Manager at VMware responsible for providing the architects and operators of the cloud infrastructure with the toolkits/frameworks and command-line interfaces they require to build a fully automated software-defined datacenter. Alan is a frequent blogger at http://blogs.vmware.com/vipowershell and has a personal blog at https://virtu-al.net. You can follow Alan on twitter as @alanrenouf.

VMworld 2012 Barcelona

I have high hopes for VMworld Barcelona, personally I had a great, if not busy time at VMworld 2012 SFO and hope to continue this in true European style in Barcelona.

I wanted to just highlight what my main plans were as one of the things that always makes VMworld for me is talking to people about what they are doing and specifically how they are using or would like to use PowerCLI or automation in general.

So, if you are attending VMworld Barcelona then please do come see me and we can have a chat.

My Schedule

EXPERTS04 – Meet the Experts – 04

Tuesday, Oct 9, 5:00 PM – 6:00 PM

Stop by the Meet the Experts Lounge to book time with a Knowledge Expert. They are available throughout the week for casual, one-to-few discussions. Please reference their availability now and stop by the Lounge reception desk in Hall 6, to schedule a 30-minute appointment.

GD33 – PowerCLI with Alan Renouf

Wednesday, Oct 10, 11:00 AM – 12:00 PM

Join me in this Group Discussion on PowerCLI and automation, I loved these in SFO hearing what people were doing and the challenges people had, come have your say ! (Book early it fills fast)

INF-VSP1252 – What’s New with vSphere 5.1 – ESXCLI & PowerCLI

Wednesday, Oct 10, 5:00 PM – 6:00 PM

Thursday, Oct 11, 1:30 PM – 2:30 PM

In this session Technical Marketing automation experts William Lam and Alan Renouf will take you through What’s New in ESXCLI and PowerCLI for the vSphere 5.1 release. In this session Alan and William will take you through the exciting features available to use when automating VMware products, both beginners and experts will learn how to use new features to make your life easier and more productive.

INF-VSP1329 – PowerCLI Best Practices: The Return!

Tuesday, Oct 9, 2:00 PM – 3:00 PM

Thursday, Oct 11, 9:00 AM – 10:00 AM

Building on the success of our PowerCLI Best Practices sessions from VMworld 2011, we want to show you our next collection of PowerCLI best practices. This session will show and demonstrate PowerCLI in all its aspects managing and automating not just VMware vSphere® but also VMware vCloud Director®, VMware® View™, VMware vShield™ and more.  Presenting with the awesome Luc Dekens.

Cloud Physics – Its Alive !

There’s a new kid on the VMware block and its Cloud Physics, they have just launched their website and also alpha system which you can sign up for.  So who are they and what have they created ?

The who’s who of Cloud Physics includes some of the smartest people I have met, some great guys with not only fantastic ideas but also a history of work with many of the VMware features you are probably using right now.

Check out their about page for a list of people and probably some names you will recognize, and with that technical advisors list how can they fail ?!

What have they produced ?

imageTheir opening beta product looks very impressive, it’s a scorecard based interface to your data providing metrics, logic and industry knowledge to the data from your own system.

Each score card shows your data and give you the information you need to do your job better, data that isn’t always easy to find in the vSphere Client can be displayed in seconds and shown in a relevant way to help system administrators concentrate on the issues or potential issues in their systems.

Try it out

As if there wasn’t enough of a reason to try their system out already, they just gave another one, and its big !

The guys at Cloud physics are also giving you a challenge, if you take part in their challenge you can win lots of shiny apple based products !

What do you have to do ?  That’s the great bit, all you have to do is register on their site and start looking around, you will instantly start gaining points.  To get more points you can suggest cards, or ways to make this more useful, some of these have already been created so take a look before adding your own.

Surely this is a win/win opportunity ?  If you suggest a good idea they may implement it and it will save you time… Win1

If you get enough points you can win a prize…. Win2

You can use their system to look at your current data and often find problems and fixes you weren’t aware were there… Win3 !

I’m checking it out and making suggestions and I have to say, I’m impressed !

The first rule of #NotSupported is…..

NotSupported

This year VMworld is going to be awesome, I have seen some things which are going to blow your mind!

One thing I am really excited about is #NotSupported, this is a group of sessions which were the brain child of VMware’s Randy Keener (@VMRandy).

Historically people have done some cool things with VMware software, often things which it wasn’t designed for or is not supported by VMware.  Randy has taken these fantastic use cases and added his own group of sessions at VMworld hosted by some of the experts from VMware and other companies and full of great information you didn’t know was possible.

  • Are you interested in nested ESXi Environments ?
  • What else can you do with the SRM SRA ?
  • Do you need help setting up your nested ESXi ?

To find out the answers to these questions and more come and listen whilst people like William Lam, Duncan Epping and many more tell you the amazing things that can be done with our software that is #NotSupported.

Where can I find these awesome sessions ?

Check out the Community Lounge at VMworld, the sessions will be hosted from 1pm – 3pm each day, for a schedule of the sessions visit this link below – make sure you add them to your calendars as you wont want to miss them, believe me! – More information will be added with the run up to VMworld.

#NotSupported Session List

The Rules

Poster

Parkour at Vargas Academy

I never do these kind of personal posts telling people what I’m doing but just for this once I wanted to make a change, I promise this is not going to turn into one of those fitness blogs, actually quite the contrary.

For a few weeks now I have been doing adult Parkour classes (Check out here for more info on Parkour) at my local gym in Scotts Valley, CA.  So this week I asked the instructor to take a few videos of the cool stuff we were learning, this is just a quick taste for what we were doing.

If you live anywhere in the Scotts Valley/Santa Cruz area I  can highly suggest coming along on a Tuesday night to give it a go, its not even like you are exercising, its just so much fun ! The instructor is amazing and it doesn’t matter how fit, or in my case unfit you are, as you can see, after even a couple of weeks they have you doing some whacky stuff !

I was told, if it aint on the net it didn’t happen, so here ya go….

Parkour at Vargas Academy from Alan Renouf on Vimeo.

Installing vCloud Adapter for vCenter Operations Manager

I had to go through the installation of the vCloud Adapter into vCenter Operations Manager today and although the steps are in the doc I couldn’t get it to work, I ended up following Kendrick Coleman’s post here, although this worked I was later informed there was a much easier way to do this.

Randy Keener who works for DevOps at VMware showed me how to do it the correct (and easier) way, as I was going through this again so I thought I would take some screen shots to make things easier for anyone else who is unable to follow documentation like me !

What’s needed

  • vCloud Director 1.5.0 or later
  • vCloud Director administrator account credentials of the System organization
  • vCloud Adapter – Download the adapter installation TGZ file anonymously from ftp://ftp.integrien.com/

 

Installing the adapter

Go to the vCOps admin page:  http://vcopsip/admin and go to the update tab

TinyGrab Screen Shot 13-08-2012 16.35.43

Click the browse button and navigate to the folder where you have extracted the adapter files from the original TGZ, select the .pak file.

TinyGrab Screen Shot 13-08-2012 16.36.12

Click the Update button and click OK to confirm the update

TinyGrab Screen Shot 13-08-2012 16.36.33

The adapter file will be uploaded to your vCOps setup.

TinyGrab Screen Shot 13-08-2012 16.36.43

Read (yeah ok then) and accept the EULA and click OK.

TinyGrab Screen Shot 13-08-2012 16.37.24

Confirm the update by clicking OK.

TinyGrab Screen Shot 13-08-2012 16.37.35

The installation will begin…

TinyGrab Screen Shot 13-08-2012 16.37.54

Once completed you will see the update status on the screen.

TinyGrab Screen Shot 13-08-2012 16.41.56

Now go to the custom web page: https://vcopsip/vcops-custom/

TinyGrab Screen Shot 13-08-2012 16.42.37

Once logged in click the Admin menu and then support

Screen Shot 2012-08-13 at 16.47.33

You will be presented with the Support page

TinyGrab Screen Shot 13-08-2012 16.48.53

Click the Info tab and press the smallest button in the world, I missed this button so many times !

image

Click yes to start the describe process.

TinyGrab Screen Shot 13-08-2012 16.49.47

A confirmation box will appear.

TinyGrab Screen Shot 13-08-2012 16.49.55

After a couple of seconds you should see our adapter in the list of adapters available.

image

 

Configuring the adapter

You should now be able to follow along with the vCOps adapter PDF which was part of the TGZ file from page 17, setting up the adapter is fairly straight forward.

Creating a custom Dashboard

As the installation doesn’t create any dashboards for you I highly recommend visiting Clint’s site and reading his great post which shows how to setup a custom Dashboard here: http://velemental.com/2012/04/12/tutorial-building-custom-dashboards-in-vcops/

PowerShell at VMworld 2012 San Francisco

Its that time again! – VMworld, and let me tell you, this year its going to be epic!

I wanted to give you a list of all the PowerShell and PowerCLI sessions listed in this years Session Catalogue for San Francisco, if you don’t have these booked make sure you add them straight away as room is running out fast !

I am personally looking forward to presenting with some superstars this year such as:

  • Luc “The Master” Dekens
  • Jake “Head in the Clouds” Robinson
  • William “API Guru” Lam
  • Eric “PowerTool” Williams
  • Aidan “I am the center of excellence” Dalgliesh

We have some great decks and some awesome demos planned, don’t miss them.  And if you see me come say hi and tell me how you use PowerCLI, you never know I may have a spare sticker, poster and badge to get rid of.

Sessions

INF-VSP1252 – What’s New with vSphere Automation

Click here to add
In this session Technical Marketing automation experts William Lam and Alan Renouf will take you through VMware Automation.You will learn which products are available, which products to use and how Automation fits into the VMware Suite of products. In this session Alan and William will take you through the exciting features available to use when automating VMware products, both beginners and experts will learn how to use new features to make your life easier and more productive. Monday, Aug 27, 2:30 PM – 3:30 PM

Wednesday, Aug 29, 9:30 AM – 10:30 AM

William Lam – Sr. Technical Marketing Engineer, VMware, Inc.

Alan Renouf – Sr. Technical Marketing Architect, VMware, Inc.

INF-BCO2155 – vCloud DR for Oxford University Computing Services – Real World Example

image
Resiliency is a key aspect of any infrastructure—it is even more important in infrastructure-as-a-service solutions. This session will include a tour of a real world vCloud DR solution deployed at Oxford University Computing Services (OUCS). Throughout the session there will be detailed guidance on how both the management and resource clusters were designed, deployed and automated. Furthermore the details of how SRM in conjunction with VMware vSphereTM PowerCLI (PowerCLI) was used to automate the end-to-end recovery of a vCloud Director–based infrastructure. This session will offer a perfect complimentary follow on from the whitepaper regarding the high-level process produced by Duncan Epping and Chris Colotti and the Automation session by Alan Renouf and Aidan Dalgleish. The paper combined with the Automation session will describe the process and the automation principles whereas this session will describe a complete real world implementation. Monday, Aug 27, 3:30 PM – 4:30 PM

Aidan Dalgleish – Consulting Architect, VMware, Inc.

Adrian Parks – Senior Systems Administrator, Oxford University Computing Services

Gary Blake – Senior Consultant, VMware, Inc.

INF-VSP1329 – PowerCLI Best Practices: The Return!

image
Building on the success of our PowerCLI Best Practices sessions from VMworld 2011, we want to show you our next collection of PowerCLI best practices. This session will show and demonstrate PowerCLI in all its aspects managing and automating not just VMware vSphere® but also VMware vCloud Director®, VMware® View™, VMware vShield™ and more Tuesday, Aug 28, 3:00 PM – 4:00 PM

Wednesday, Aug 29, 8:00 AM – 9:00 AM

Alan Renouf – Sr. Technical Marketing Architect, VMware, Inc.

Luc Dekens – Systems Engineer, Eurocontrol Maastricht.

INF-VSP2448 – Automating Bare Metal to the Cloud and Beyond

image
When working in the cloud automation is key, working at the scale of the cloud VMware customers need an easy and reliable method of deployment which gives guaranteed results 100% of the time. Cisco, VMware and Bluelock will show you how to automate the build of your complete vCloud Director Infrastructure from the bare metal up to the cloud and beyond. Learn how PowerShell can be used to create a single easily readable and adaptable script to ensure your system is built quickly and efficiently, watch as a system is built before your very eyes with no magic tricks or rabbits in sight. Tuesday, Aug 28, 12:00 PM – 1:00 PM

Eric Williams – Technical Marketing Engineer, Cisco Systems Inc.

Alan Renouf – Sr. Technical Marketing Architect, VMware, Inc.

Jake Robinson – Solutions Architect, BlueLock

INF-VSP1856 – Become a Rock Star with PowerCLI and vCenter Orchestrator

image
Automation is the future of cloud, and in this session attendees will learn how to identify areas in their environment that are primed for less administrator interaction. The combination of PowerCLI and VMware® vCenter™ Orchestrator puts considerable power in even the greenest users. Attendees will learn how to identify areas for automation and start learning to discern which tool is best suited for the job and when to use them together. Monday, Aug 27, 4:00 PM – 5:00 PM

Josh Atwell – Systems Administrator, Cisco Systems Inc.

INF-VSP2164 – Automation of vCloud Director Disaster Recovery

image
Resiliency is a key aspect of any infrastructure—it is even more important in infrastructure-as-a-service solutions. This session will include guidance, examples and demonstrations of the use of VMware vSphereTM PowerCLI (PowerCLI) to automate the recovery of a vCloud Director–based infrastructure. In particular the session will focus on the automation of the recovery steps for vCloud Director managed vApp workloads, that cannot be recovered with vSphere Site Recovery Manager (SRM). This session will offer a perfect complimentary follow on from the whitepaper regarding the high-level process released by Duncan Epping and Chris Colotti. The paper discussed the process and this session will describe the automation Tuesday, Aug 28, 4:30 PM – 5:30 PM

Alan Renouf – Sr. Technical Marketing Architect, VMware, Inc.

Aidan Dalgleish – Consulting Architect, VMware, Inc.

Group Discussions

GD27 – PowerCLI with Alan Renouf

image
During this group discussion we will talk about what can be automated, discuss the merits of using PowerShell and PowerCLI, show examples and talk about the best methods of achieving integration. We will also discuss tips and tricks you have learned and the best methods for automating the VMware products. Come prepared with examples and questions and remember this is a Group Discussion! Monday, Aug 27, 10:30 AM – 11:30 AM

Thursday, Aug 30, 12:00 PM – 1:00 PM

Alan Renouf – Sr. Technical Marketing Architect, VMware, Inc.

Hands on Labs

HOL-INF-10 – Script and Develop Your Cloud Solution with PowerCLI and the vSphere Web Client SDK

This lab is presented as two 30 minute lightning labs to help you extend your VMware solution. The PowerCLI module covers automating vSphere and vCloud Director. Novice users will learn to use the tool and more advanced users will get familiar with the new functionality available in the latest release of the product. You will walk away with a better understanding of PowerCLI and how it can help you in your day-to-day work. The vSphere Web Client SDK module teaches you several techniques for extending the vSphere Web Client. The goal of this module is to demonstrate the close integration that is possible with the vSphere Web Client SDK, and the ease with which you can integrate your own solutions into the vSphere Web Client. HOL

Attend the self paced Hands on Lab.

Videos

Still cant decide ?  Take a look at some of the session videos where the presenters explain more information…..

Indianapolis VMUG User Conference – 26th July 2012

image

Next week I will be presenting at the Indianapolis VMUG User Conference, yet another VMUG I have never been to but I hear great things about, im looking forward to catching up with the usual VMUG frequenters and also some of the local folk.

I will be presenting the following sessions , if you are at the VMUG make sure you attend or at least come by and say Hi!

VMware PowerCLI

This will take place in the Sagamore 5-7 room and will be at 11:00 – 11:45

Tired of clicking the Next, Next, Next, button for those simple jobs ?

Do you have a vSphere or vCD task you repeat every month, week, day or even hour ?

Join me in this PowerCLI session as I take you from beginner to Scripting Ninja.  In this session I will show you not only how to use PowerCLI but also how to teach yourself, I will show you the great resources available on the internet and how to take PowerCLI to the next level.

If you do it more than once, come learn how to script it!

Event Details

Thursday, July 26, 2012
8:00 a.m. – 5:00 p.m.

Indiana Convention Center
100 S. Capitol Avenue
Indianapolis, IN 46225

Make sure you register here before attending.

Agenda

A copy of the full agenda and other sessions taking place can be found here: http://www.vmug.com/index.php?mo=cm&op=ld&fid=201

Installing PowerShell Web Access on Windows 2012 RC Core

Recently I wanted to check out the Windows 2012 RC build and more specifically some of the new PowerShell features.  I have seen the Web Access mentioned a few times now so wanted to deploy a quick box to test this out.

I decided to try windows core and see how easy it was to get started with PowerShell Web Access, after the install which was very fast I changed my Administrator password and then logged into the box, I was immediately presented with a command prompt, the following steps are what I took to add PowerShell Web Access into my test environment.

Step by Step

Step 1 was to launch PowerShell and add the windows feature for PowerShell Web Access

TinyGrab Screen Shot 05-06-2012 20.31.43

Next I setup the certificates, note that I just used the test certificates as this was a test box but if you are installing this in live you should use the help on Install-PswaWebApplication to see the further parameters needed for a proper certificate.

TinyGrab Screen Shot 05-06-2012 20.36.58

Next I added a single rule to allow the local Administrator access to this machine, again you can obviously setup the rules as needed in your environment with this cmdlet.

TinyGrab Screen Shot 05-06-2012 23.31.00

After this has been completed you should now be able to visit the https site to receive a login window, in my example the URL was https://hostname/pswa

TinyGrab Screen Shot 05-06-2012 23.05.03

Here you must enter the credentials to login to the host…

TinyGrab Screen Shot 05-06-2012 23.29.38

Once logged in you should have a familiar window, as you can see I issued a Get-Command to list all the cmdlets available to me…

TinyGrab Screen Shot 05-06-2012 23.31.50

VMworld Session Voting

Disclaimer: This lady will not be at my session!I’m sure by now you have already seen that the VMworld Voting is open which means its time to have your say on what you want to see at VMworld, if you have not yet signed up for a VMworld account so that you can vote then please do so by following this link.

Now I could do the normal “Vote for me because because PowerCLI will solve world famine” post but I thought I would do something different to the rest, what I’m going to do is just use the coolness of PowerShell to allow you to find my sessions, once you have them on your screen have a read of them for yourself and then you can decide if you ant to vote for them or not.

You can do that by simply changing the username and password parts of the script below and allowing it to log into the VMworld site and display my sessions for you.  This will of course not click the “Vote” button as that would be cheating, it will however give you a nice list of my sessions where you can click to get further information.

If however you like what you see and want to vote then just click the thumb picture to make it green and I will thank you forever more and we will see what we can do about world famine.

Use the Script

$VMworldUser = "myvmworldusername"
$VMworldPassword = "myvmworldpassword"
# Replace the username and password above

$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$ie.navigate("http://www.vmworld.com/www.vmworld.com/cfp-login!input.jspa")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("username01").value= $VMworldUser
$ie.document.getElementById("password01").value = $VMworldPassword
$ie.document.getElementById("loginformaction").submit()
while($ie.Document.url -ne "https://vmworld2012.activeevents.com/scheduler/publicVoting.do") {start-sleep -s 7}
$ie.document.getElementById("searchEl").value = "Renouf"
$ie.Document.getElementById("displayOptionsForm").submit()

Overview

Here are a list of the submissions I have put forward for VMworld this year:

image

Updated Script to remediate VDS/SvMotion issue

Following my recent post where I showed how we could search for and fix any VMs which had an issue after being Storage vMotioned and attached to a VDS I received a couple of emails from people with a few issues.

Firstly the script was written using the VDS PowerShell fling (Check it out, its cool), some people were not able to use this fling in production systems as it is not officially supported by VMware.

Secondly the fling only supported VDS and not the Nexus 1kv, some customers had this issue with the N1KV so needed a resolution.

The good news…

I have re-written the script to no longer use the fling but instead use the raw API’s, this means all you now need is PowerCLI 5.0.1 and you can run the below script in the same way as before to check and remediate for issues.

Thanks goes to Luc who came up with an easy way to check for free ports on the VDS here.

Remember this does not fix the issue completely, only a patch from VMware will do that but it does however tell you if you have the issue and plug the gap temporarily.

Just as a reminder, here is how the script is used:

Using the script

To check the VMs we can easily pipe a list of VMs into our function which can be seen below.  This can be all VMs in a Cluster, all VMs on a particular host or any other list of VMs you can think of, for my examples below I have shown all VMs attached to a vCenter

image

As you can see from the above screenshot, all VMs are fine apart from VM12 which currently has the problem described in Duncan’s article,  now to fix the issue.

We can use the same script with a –Fix parameter which allows us to fix the issue, when fixing the issue the script will move each of the VMs network connections to a new port on the same portgroup and then move it back again to its original port.   If no free ports are available the script will expand your portgroup temporarily and then decrease the ports when finished.

image

As you can see from the above screenshot, the issue has now been resolved for this VM by using the function with the –Fix parameter and further running of the script in test mode will show all are now fine.

The Script

Function Get-FreeVDSPort ($VDSPG) {
	$nicTypes = "VirtualE1000","VirtualE1000e","VirtualPCNet32","VirtualVmxnet","VirtualVmxnet2","VirtualVmxnet3"
	$ports = @{}

	# Get all the portkeys on the portgroup
	$VDSPG.ExtensionData.PortKeys | Foreach {
		$ports.Add($_,$VDSPG.Name)
	}

	# Remove the portkeys in use  Get-View
	$VDSPG.ExtensionData.Vm | Foreach {
	    $VMView = Get-View $_
		$nic = $VMView.Config.Hardware.Device | where {$nicTypes -contains $_.GetType().Name -and $_.Backing.GetType().Name -match "Distributed"}
	    $nic | where {$_.Backing.Port.PortKey} | Foreach {$ports.Remove($_.Backing.Port.PortKey)}
	}

	# Assign the first free portkey
	if ($ports.Count -eq 0) {
		$null
	} Else {
		$ports.Keys | Select -First 1
	}
}

Function Set-VDSPGNumPorts ($VDSPG, $NumPorts) {
	$spec = New-Object VMware.Vim.DVPortgroupConfigSpec
    $spec.numPorts = $NumPorts
	$spec.ConfigVersion = $VDSPG.ExtensionData.Config.Configversion
    $VDSPG.ExtensionData.ReconfigureDVPortgroup($spec)
}

Function Test-VDSVMIssue {
	Param (
		[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
        [PSObject[]]$VM,
		[switch]$Fix
	)
	Process {
		Foreach ($VMachine in $VM){
			Foreach ($NA in ($VMachine | Get-NetworkAdapter)) {
				$VMName = $VMachine.Name
				If (($NA.ExtensionData.Backing.GetType()).Name -eq "VirtualEthernetCardDistributedVirtualPortBackingInfo") {
					$PortKey = $NA.ExtensionData.Backing.Port.PortKey
					$vSwitchID = $NA.ExtensionData.Backing.Port.SwitchUUID
					$Datastore = (($VMachine.ExtensionData.Config.Files.VmPathName).split("]")[0]).Replace("[","")
					$filename = "$($datastore):\.dvsData\$vSwitchID\$PortKey"
					if (-not (Get-PSDrive $datastore -ErrorAction SilentlyContinue)) {
						$NewDrive = New-PSDrive -Name $Datastore -Location (Get-Datastore $Datastore) -PSProvider VimDatastore -Root '\'
					}
					$filecheck = Get-ChildItem -Path $filename -ErrorAction SilentlyContinue
					if ($filecheck) {
						Write-Host -ForegroundColor Green "$VMName $($NA.Name) is OK"
					} Else {
						Write-Host -ForegroundColor Red "Problem found with $VMName $($NA.Name)"
						If ($Fix) {
							Write-Host -ForegroundColor Yellow "Fixing issue..."
							$VDSPG = Get-VirtualPortGroup -Distributed -Name $NA.NetworkName
							$DVPort = $null
							Write-Host -ForegroundColor Yellow "..Finding free port on $($NA.NetworkName)"
							$DVPort = Get-FreeVDSPort $VDSPG
							$Move = $True
							if (-not $DVPort) {
								Write-Host -ForegroundColor Yellow "..No free ports found on $($VDSPG.Name), adding an additional port"
								If (($VDSPG.ExtensionData.Config.Type -ne "lateBinding") -and ($VDSPG.ExtensionData.Config.Type -ne "earlyBinding")) {
									Write "Unable to add a port to $($NA.NetworkName) since dvportgroup is configured as $($VDSPG.PortBinding)"
									Write-Host -ForegroundColor Red "Problem still exists with $VMName please resolve manually"
									$Move = $false
								} Else {
									$CurrentPorts = $VDSPG.NumPorts
									$NewTotalPorts = $VDSPG.NumPorts + 1
									Set-VDSPGNumPorts -VDSPG $VDSPG -NumPorts $NewTotalPorts
									$PGAdded = $true
									$VDSPG = Get-VirtualPortGroup -Distributed -Name $NA.NetworkName
									$DVPort = Get-FreeVDSPort $VDSPG
								}
							}
							If ($Move){
								Write-Host -ForegroundColor Yellow "..Moving $($NA.Name) to another free port on $($VDSPG.Name)"
								$NA | Set-NetworkAdapter -PortKey $DVPort -DistributedSwitch $VDSPG.VirtualSwitch -Confirm:$false | Out-Null
								Write-Host -ForegroundColor Yellow "..Moving $($NA.Name) back to port $PortKey"
								$NA | Set-NetworkAdapter -PortKey $PortKey -DistributedSwitch $VDSPG.VirtualSwitch -Confirm:$false | Out-Null
								Write-Host -ForegroundColor Yellow "..Checking changes were completed"
								$filecheck = Get-ChildItem -Path $filename -ErrorAction SilentlyContinue
								if ($filecheck) {
									Write-Host -ForegroundColor Green "$VMName $($NA.Name) is now fixed and OK"
								} Else {
									Write-Host -ForegroundColor Red "Problem still exists with $VMName please resolve manually"
								}
								If ($PGAdded) {
									Write-Host -ForegroundColor Yellow "..Removing the added port on $($VDSPG.Name)"
									Set-VDSPGNumPorts -VDSPG $VDSPG -NumPorts $CurrentPorts
									$PGAdded = $false
								}
							}
						}
					}
				} Else {
					Write-Host -ForegroundColor Green "$VMName is not connected to a dvSwitch so this issue is not relevant."
				}
			}
		}
		Get-PSDrive | Where { ($_.Provider -like "*VimDatastore") -and ( $_.Name -notlike "*vmstore*")} | Foreach {
			Remove-PSDrive $_ | Out-Null
		}
	}
}

# Example code to check all VMs attached to vCenter for the issue:
# Get-VM | Test-VDSVMIssue

# Example code to fix all VMs attached to vCenter:
# Get-VM | Test-VDSVMIssue -Fix

# Example code to fix all VMs in Cluster01 for the issue:
# Get-Cluster01 | Get-VM | Test-VDSVMIssue

# Example code to fix all VMs in Cluster01:
# Get-Cluster01 | Get-VM | Test-VDSVMIssue -Fix