1

I am trying to load a PowerShell module that executes a custom cmdlet function but I can't get it to load... I've applied the solutions of several previous questions, but now I'm just going in circles. Here are the specs of what I have done so far and the specific error that returns. Note that as I am new to PowerShell and programming in general, it wouldn't surprise me that my problem isn't a file path issue but a logic error in my actual function:

  1. I created a profile function for a custom cmdlet that allows me to open project files from two different paths:

           function push-project( $project )
        {
            pushd ~/Documents/Visual Studio 2015/Projects/$project;
            pushd ~/Documents/GitHub/$project;
        }
    
    New-Alias -Name pp -Value push-project;
    
  2. I created a module by saving the function as ProfileFunctions.psm1 in the following directory:

    ~\Documents\WindowsPowerShell\Modules\ProfileFunctions\ProfileFunctions.psm1

  3. To invoke the function, per its syntax, I type in pp $projectName into the PS console window, but the error that returns is standard not recognized:

    pp : The term 'pp' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
    spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:1

    • pp MyFirstApp
    • ~~
    • CategoryInfo : ObjectNotFound: (pp:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException
6
  • 2
    What happens if you Import-Module ProfileFunctions ? Commented Aug 8, 2015 at 20:46
  • Does it work if you use the regular function name? Commented Aug 8, 2015 at 21:06
  • @Eris, I get a "no valid module file exists" error when I attempt to import. So I guess PS isn't even creating one in the first place. Commented Aug 8, 2015 at 21:17
  • 1
    If your module exists, it will be listed when you run Get-Module -ListAvailable. That said, if your goal is simply to load that function into your powershell environment, I would rather just use the $profile (do you know what I mean)? Or do you have another reason to use a module? Commented Aug 9, 2015 at 9:47
  • 1
    @ElliotEwert I use custom functions in my profile. So going a bit of topic here, but in case it helps - to create a profile (if you don't have one) you can run New-Item -Type file $profile, then e.g. ise $profile to edit that file. If you add your function and alias in there it should work. Powershell auto-loads the $profile every time you open Powershell. It might block you with the execution policy which you can set with Set-ExecutionPolicy RemoteSigned. Sorry if you know all this already. Commented Aug 10, 2015 at 15:37

2 Answers 2

2

I copied and pasted your code into a Windows 8.1 machine I have here. It worked great (apart from the folder names not existing, since I don't have Visual Studio).

Things off the top of my head that might stop your module from working:

The file is actually called ProfileFunctions.psm1.ps1 or ProfileFunctions.psm1.txt or something.

The Modules folder is saved in someone else's documents folder, or the Public documents folder.

You've accidentally put a space in the folder name (it must be WindowsPowerShell, not Windows PowerShell).

Sign up to request clarification or add additional context in comments.

1 Comment

Your guess is correct, the fact that the hidden file extension is '.psm1.ps1' part of the problem. As it turns out, once I corrected this, the solution @Jower is also applicable. Thank you.
1

I Think your problem is that the Alias pp is not exported from the module.

You either define the alias outside the module, as supposed to or explicitly export it from the module using.

Export-ModuleMember -Function pushproject -Alias pp

Find more details in this article Unable to Create a Powershell Alias in a script Module

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.