Updating your PowerCLI module

When updating your PowerCLI module you may find that some modules cant be upgraded if they are in use.

This tends to occur if you modify your powershell profile to import the vmware.powercli module when you start powershell.

The manul work around for this is

  • Stop all running instances of powershell (taskmgr to kill powershell.exe and powershell_ise.exe  if needed)
  • run a command prompt as  admin
  • Start “powershell -noprofile”
  • then in powershell run “Find-Module Vmware.PowerCLI | Install-module -scope Allusers -force”

Ive written a function to perform the same actions so that you can update the PowerCLI module to the latest online version by performing the above actions automatically.

 

The function uses previous post to create an admin session powershell and then runs a generated script to update powercli in that session.

The new session script will also close all other powershell sessions meaning its the only one running and can then update powercli sucessfully.