Use the "PowerShell Community Extensions" in "After Build Script"

Daniel Häfele's Avatar

Daniel Häfele

17 Dec, 2014 08:52 PM

Hey guys,

I'm trying to use the PowerShell Community Extensions in my "After build script", but sadly, this module is not available.

I install it in the "install script" via chocolatey: "choco install pscx";

This is the log of the install script:
6Chocolatey (v0.9.8.27) is installing 'pscx' and dependencies. By installing you accept the license for 'pscx' and each dependency you are installing.
7
8pscx v3.2.0
9Downloading pscx 32 bit
10 from 'https://pscx.codeplex.com/downloads/get/923562'
11Installing pscx...
12pscx has been installed.
13pscx has finished successfully! The chocolatey gods have answered your request!
14Finished installing 'pscx' and dependencies - if errors not shown in console, none detected. Check log for errors if unsure.

And I get the following error if I try to import the pscx module:
73Import-Module : The specified module 'pscx' was not loaded because no valid module file was found in any module directory.
74At line:1 char:1
75+ Import-Module pscx;
76+ ~~~~~~~~~~~~~~~~~~
77 + CategoryInfo : ResourceUnavailable: (pscx:String) [Import-Module], FileNotFoundException
78 + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
79
80Command executed with exception: The specified module 'pscx' was not loaded because no valid module file was found in any module directory.

  1. Support Staff 1 Posted by Feodor Fitsner on 17 Dec, 2014 09:03 PM

    Feodor Fitsner's Avatar

    I think the problem is that PSModulePath is not getting updated by Chocolatey (*or* it's set but not refreshed in the current build session).

    Get know where that module is being installed and after installation explicitly refresh PSModulePath:

    SET PSModulePath=<folder-where-chocolatey-installs-ps-modules>;%PSModulePath%
    

    Then try loading the module.

  2. 2 Posted by Daniel Häfele on 18 Dec, 2014 07:58 AM

    Daniel Häfele's Avatar

    Nice, that seems to have done the trick.
    For your interest, here's my code:

    $pscxPath = "C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx";
    
    if (-not (Test-Path $pscxPath))
    {
        $pscxPath = $null;
        Write-Host "Searching for the pscx powershell module.";
        $pscxPath = (Get-ChildItem -Path "C:\Program Files\" -Filter "pscx.dll" -Recurse).FullName;
        if (!$pscxPath) { $pscxPath = (Get-ChildItem -Path "C:\Program Files (x86)\" -Filter "pscx.dll" -Recurse).FullName; }
        $pscxPath = Split-Path $pscxPath;
        Write-Host "Found it at " + $pscxPath;
    }
    
    $env:PSModulePath = $env:PSModulePath + ";" + $pscxPath;
    
  3. Support Staff 3 Posted by Feodor Fitsner on 18 Dec, 2014 08:01 AM

    Feodor Fitsner's Avatar

    Great, thanks for the update and code snippet!

  4. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 01:53 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac