VMware Cloud Community
MBreidenbach0
Hot Shot
Hot Shot
Jump to solution

Cleanup PowerCLI 6.5.x old directories after update-module ?

I noticed that when I update-module PowerCLI the old versions aren't removed.

Is there a way to cleanup this ? i.e. automatically remove the old module versions ?

Of course I can do this manually but hey we are automating stuff here :smileygrin:

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Tested again, and I can confirm it is the Force parameter that bypasses the WhatIf, and actually removes the modules.

So to test, run with -WhatIf.

When happy with the result, run with -Force -Confirm:$false

The Force is required to avoid errors due to inter-module dependencies.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

8 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this.

When you're happy with the output, remove the WhatIf switch from the Uninstall-Module cmdlet

Get-Module -Name VMware* -ListAvailable |

Group-Object -Property Name | where{$_.Group.Count -gt 1} | %{

    $_.Group | Sort-Object -Property Version -Descending | select  -Skip 1 | %{

        Uninstall-Module -Name $_.Name -RequiredVersion $_.Version -Force -Confirm:$false -WhatIf

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

MBreidenbach0
Hot Shot
Hot Shot
Jump to solution

6 Minutes... that's fast :smileygrin:

That worked... but it worked better than expected. It did remove the old modules.... with -Confirm:$true -WhatIf... and it didn't ask me...

PS C:\PowerCLI\_> Get-Module -Name VMware.* -ListAvailable | Select-Object -Property Name,Version

Name                                Version

----                                -------

VMware.DeployAutomation             6.5.1.6997673

VMware.DeployAutomation             6.5.1.5299608

VMware.ImageBuilder                 6.5.1.6997673

VMware.ImageBuilder                 6.5.1.5299608

VMware.PowerCLI                     6.5.4.7155375

VMware.PowerCLI                     6.5.3.6870460

VMware.PowerCLI                     6.5.2.6268016

VMware.PowerCLI                     6.5.1.5377412

VMware.VimAutomation.Cis.Core       6.5.4.6983166

VMware.VimAutomation.Cis.Core       6.5.3.6870462

VMware.VimAutomation.Cis.Core       6.5.2.6230110

VMware.VimAutomation.Cis.Core       6.5.1.5374323

VMware.VimAutomation.Cloud          6.5.1.5375799

VMware.VimAutomation.Common         6.5.4.6979861

VMware.VimAutomation.Common         6.5.1.5335010

VMware.VimAutomation.Core           6.5.2.6234650

VMware.VimAutomation.Core           6.5.1.5374329

VMware.VimAutomation.HA             6.5.4.7147627

VMware.VimAutomation.HA             6.0.0.5314477

VMware.VimAutomation.HorizonView    7.1.0.5307191

VMware.VimAutomation.License        6.5.1.5375648

VMware.VimAutomation.Nsxt           2.0.0.6870461

VMware.VimAutomation.PCloud         6.5.1.5376282

VMware.VimAutomation.Sdk            1.0.0.5334677

VMware.VimAutomation.Srm            6.5.1.5374694

VMware.VimAutomation.Storage        6.5.4.7154886

VMware.VimAutomation.Storage        6.5.1.5374001

VMware.VimAutomation.StorageUtility 1.1

VMware.VimAutomation.StorageUtility 1.0

VMware.VimAutomation.Vds            6.5.1.5374428

VMware.VimAutomation.Vmc            6.5.4.7086404

VMware.VimAutomation.vROps          6.5.1.5375723

VMware.VumAutomation                6.5.1.5301639

PS C:\PowerCLI\_> Get-Module -Name VMware* -ListAvailable |

>> Group-Object -Property Name | where{$_.Group.Count -gt 1} | %{

>>     $_.Group | Sort-Object -Property Version -Descending | select  -Skip 1 | %{

>>         Uninstall-Module -Name $_.Name -RequiredVersion $_.Version -Force -Confirm:$true -WhatIf

>>     }

>> }

>>

PS C:\PowerCLI\_> Get-Module -Name VMware.* -ListAvailable | Select-Object -Property Name,Version

Name                                Version

----                                -------

VMware.DeployAutomation             6.5.1.6997673

VMware.ImageBuilder                 6.5.1.6997673

VMware.PowerCLI                     6.5.4.7155375

VMware.VimAutomation.Cis.Core       6.5.4.6983166

VMware.VimAutomation.Cloud          6.5.1.5375799

VMware.VimAutomation.Common         6.5.4.6979861

VMware.VimAutomation.Core           6.5.2.6234650

VMware.VimAutomation.HA             6.5.4.7147627

VMware.VimAutomation.HorizonView    7.1.0.5307191

VMware.VimAutomation.License        6.5.1.5375648

VMware.VimAutomation.Nsxt           2.0.0.6870461

VMware.VimAutomation.PCloud         6.5.1.5376282

VMware.VimAutomation.Sdk            1.0.0.5334677

VMware.VimAutomation.Srm            6.5.1.5374694

VMware.VimAutomation.Storage        6.5.4.7154886

VMware.VimAutomation.StorageUtility 1.1

VMware.VimAutomation.Vds            6.5.1.5374428

VMware.VimAutomation.Vmc            6.5.4.7086404

VMware.VimAutomation.vROps          6.5.1.5375723

VMware.VumAutomation                6.5.1.5301639

PS C:\PowerCLI\_>

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Just tested, and indeed it does.

Must be the combination of Force and WhatIf.

But that really looks like a bug, I'll investigate further


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

MBreidenbach0
Hot Shot
Hot Shot
Jump to solution

I'm suspecting something about -force too. The dark side of the -force ?

I still have at least one VM here with old PowerCLI stuff where I can take a snapshot first. Maybe I'll try tomorrow. If that stretched cluster datacenter failover test that we are doing tomorrow is successful...

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Tested again, and I can confirm it is the Force parameter that bypasses the WhatIf, and actually removes the modules.

So to test, run with -WhatIf.

When happy with the result, run with -Force -Confirm:$false

The Force is required to avoid errors due to inter-module dependencies.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

MBreidenbach0
Hot Shot
Hot Shot
Jump to solution

Just tested it and can confirm that it works that way.

Thank you very much for your assistance !

dzak64
Enthusiast
Enthusiast
Jump to solution

I am trying to totally remove PowerCLI and reinstall, but I am unable to uninstall.

I have tried the commands in this discussion - not help.

I have also tried :

Get-Module vmware* -ListAvailable | Uninstall-Module -Force

When I run the following command

Get-Module -Name VMware.* -ListAvailable | Select-Object -Property Name,Version

I get the following:

Name                                Version

----                                -------

VMware.DeployAutomation             6.5.1.6997673

VMware.DeployAutomation             6.5.1.6997673

VMware.Hv.Helper                    1.1

VMware.ImageBuilder                 6.5.1.6997673

VMware.ImageBuilder                 6.5.1.6997673

VMware.PowerCLI                     6.5.4.7155375

VMware.PowerCLI                     6.5.4.7155375

VMware.VimAutomation.Cis.Core       6.5.4.6983166

VMware.VimAutomation.Cis.Core       6.5.4.6983166

VMware.VimAutomation.Cloud          6.5.1.5375799

VMware.VimAutomation.Cloud          6.5.1.5375799

VMware.VimAutomation.Common         6.5.4.6979861

VMware.VimAutomation.Common         6.5.4.6979861

VMware.VimAutomation.Core           6.5.2.6234650

VMware.VimAutomation.Core           6.5.2.6234650

VMware.VimAutomation.HA             6.5.4.7147627

VMware.VimAutomation.HA             6.5.4.7147627

VMware.VimAutomation.HorizonView    7.1.0.5307191

VMware.VimAutomation.HorizonView    7.1.0.5307191

VMware.VimAutomation.License        6.5.1.5375648

VMware.VimAutomation.License        6.5.1.5375648

VMware.VimAutomation.Nsxt           2.0.0.6870461

VMware.VimAutomation.Nsxt           2.0.0.6870461

VMware.VimAutomation.PCloud         6.5.1.5376282

VMware.VimAutomation.PCloud         6.5.1.5376282

VMware.VimAutomation.Sdk            1.0.0.5334677

VMware.VimAutomation.Sdk            1.0.0.5334677

VMware.VimAutomation.Srm            6.5.1.5374694

VMware.VimAutomation.Srm            6.5.1.5374694

VMware.VimAutomation.Storage        6.5.4.7154886

VMware.VimAutomation.Storage        6.5.4.7154886

VMware.VimAutomation.StorageUtility 1.1

VMware.VimAutomation.StorageUtility 1.1

VMware.VimAutomation.Vds            6.5.1.5374428

VMware.VimAutomation.Vds            6.5.1.5374428

VMware.VimAutomation.Vmc            6.5.4.7086404

VMware.VimAutomation.Vmc            6.5.4.7086404

VMware.VimAutomation.vROps          6.5.1.5375723

VMware.VimAutomation.vROps          6.5.1.5375723

VMware.VumAutomation                6.5.1.5301639

VMware.VumAutomation                6.5.1.5301639

Any ideas?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Under which scope were the modules installed, CurrentUser or AllUsers?
If AllUsers, you need to do the uninstall from a PS session that runs as administrator.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos