3

I am trying to run a PowerShell script to uninstall owncloud-client from my Windows 10 virtual machine. The code shown below can be found at

https://chocolatey.org/packages/owncloud-client (tools\chocolateyUninstall.ps1)

I would like just to test the code by running it from PowerShell to see if it actually uninstalls the software.

$unfile = "ownCloud\uninstall.exe"

if (Test-Path "${Env:ProgramFiles(x86)}\$unfile") {
  $unpath = "${Env:ProgramFiles(x86)}\$unfile"
} else {
  $unpath = "${Env:ProgramFiles}\$unfile"
}

Uninstall-ChocolateyPackage 'owncloud-client' 'exe' '/S' "$unpath"

I run script from the directory that contains it by typying:

.\chocolateyUninstall.ps1

As output I get the following error:

Uninstall-ChocolateyPackage  is not recognized as the name of cmdlet, function, script file, or operable program.

The Uninstall-ChocolateyPacakge.ps1 package is provided by chocolatey. I checked on my machine and this package is present under:

C:\ProgramData\chocolatey\helpers\functions\Uninstall-ChocolateyPackage.ps1

but still it is not recognized as cmdlet by powershell. How can I solve this problem? thanks

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
diegus
  • 1,168
  • 2
  • 26
  • 57
  • I am not familiar with this at all so I recommend you put more details in your question. What are you trying to run? `Uninstall-ChocolateyPackage`? Or `Uninstall -ChocolateyPackage`? – slybloty Feb 22 '16 at 16:47
  • I tried them both, none of them works. The on that should work is `Uninstall-ChocolateyPackage` – diegus Feb 22 '16 at 16:50
  • It very very confusing to me what steps you're taking, what scripts you're running, and which give you the errors. – slybloty Feb 22 '16 at 16:52
  • @slybloty check the edit. I am running the all script I posted and I get the error you see below it. – diegus Feb 22 '16 at 17:00
  • The error tells you that `Uninstall-ChocolateyPackage` is not defined anywhere. Aren't you supposed to be running `chocolateyUninstall`? Again, you need to better explain what you're doing. What is `Uninstall-ChocolateyPackage`? And where is it? – slybloty Feb 22 '16 at 17:10
  • @slybloty check the edit – diegus Feb 23 '16 at 09:40

2 Answers2

5

When running the installation/uninstallation scripts, Chocolatey first includes the Chocolatey PowerShell module. This is done in the background, and normally, the end user doesn't need to worry about it.

For what you are trying to do, you will need to first do an Import-Module on the Chocolatey module, to bring it into the current PowerShell session. You can find this here:

old: C:\ProgramData\chocolatey\lib\chocolatey\tools\chocolateyInstall\helpers\chocolateyInstaller.psm1

new: C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1

That should allow you to test the script directly.

Alternatively, you could run the install of the package, and then run the uninstall to see if it works as well.

A Code Cow
  • 45
  • 1
  • 5
Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60
  • 1
    In case anyone finds this via Google, the path is now updated to `C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1`. – Sumo Jul 06 '16 at 06:02
1

With the latest moderation tools, you don't need to check every package (I mean, unless it makes you feel safer). You can always check the automated tests. There's a status dot to the right of the package title.

enter image description here

You can find the test summary

owncloud-client v2.1.1.5837 - Passed - Package Test Results

https://chocolatey.org/packages/owncloud-client/2.1.1.5837 Tested 10 Feb 2016 12:51:22 +00:00 Tested against win2012r2x64 (Windows Server 2012 R2 x64) Tested with the latest version of choco, possibly a beta version. Tested with chocolatey-package-verifier service v0.4.0-15-g979d0cc Install was successful. Uninstall was successful.

https://gist.github.com/choco-bot/45f343e23cc12e101130#file-_summary-md

or explore the uninstall log directly.

https://gist.github.com/choco-bot/45f343e23cc12e101130#file-uninstall-txt

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
  • And, if you are really keen, you can use a local version of the package verifier, from here: https://github.com/chocolatey/chocolatey-test-environment – Gary Ewan Park Feb 24 '16 at 21:26
  • **NOTE:** Currently, the package verifier doesn't failing packages on erroring during uninstallation, only installation. This will change at some point though. – Gary Ewan Park Feb 24 '16 at 21:26