title: PowerShell 5.1 - How to uninstall module which is currently use
body: <p>We are using some PowerShell modules in one deployment PowerShell script. Using following command we are installing module (i.e. XXXX) into "C:\Program Files\WindowsPowerShell\Modules".</p>
  
  <pre><code>Install-Module -Name "XXXX" -AllowClobber -RequiredVersion "XXXX" -Repository "XXXX" -Scope AllUsers
  </code></pre>
  
  <p>Now once we used the functionality of this module, we uninstall it at the end of deployment script using following command.</p>
  
  <pre><code>Remove-Module -Name "XXXX" -force
  Uninstall-Module -Name "XXXX"  -AllVersions -force
  </code></pre>
  
  <p>But this uninstall module command gives following error.</p>
  
  <pre><code>WARNING: The version '###' of module 'XXXX' is currently in use. Retry the operation after closing the
  applications.
  PackageManagement\Uninstall-Package : Module 'XXXX' is in currently in use.
  At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:2046 char:21
  + ...        $null = PackageManagement\Uninstall-Package @PSBoundParameters
  +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Packag
     e], Exception
      + FullyQualifiedErrorId : ModuleIsInUse,Uninstall-Package,Microsoft.PowerShell.PackageManagement.Cmdlets.Uninstall
     Package
  </code></pre>
  
  <p>Does anybody have any idea to resolve this? </p>