Creating Script Modules

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Amandeep Bhatia Amandeep Bhatia 3 years, 6 months ago.

  • Author
    Posts
  • #10934
    Profile photo of Amandeep Bhatia
    Amandeep Bhatia
    Participant

    I have 3 powershell scripts that I created. Now, I want to deploy them to a common server to which various users will have access(using powershell web access) and they can issue cmdlets that I created.

    Initially I thought, it would be a pretty simple process. But may be I was wrong or may be I am missing something.

    To create a Script module, I copied all my scripts into a single psm1 file.
    Next step was how to make sure this is registered. I followed below post to register the module file.
    http://msdn.microsoft.com/en-us/library/windows/desktop/dd878350(v=vs.85).aspx

    But for some reason I am still not able to see my cmdlets in new session. Are there any clear steps i can follow or what is it i am not doing correctly.

    Again, i was not able to edit the PSModulePath using the script in above link so i edited the env variable manually and added my module path. Still i dont see my cmdlets. Please help!

    Thanks for the anticipation in advance.

  • #10938
    Profile photo of Don Jones
    Don Jones
    Keymaster

    What matters is WHERE and HOW you edited your PSModulePath environment variable. You can't do it from within PowerShell – that won't change anything more than the current session. You need to persistently change PSModulePath by changing it from the Windows Control Panel or via GPO.

    And you're technically not "registering" the module. It simply needs to live in a place where PowerShell knows to look for it, if you want module auto-loading and auto-discovery to work.

    You should be able to open a new shell session, run "$env:psmodulepath", and see your revised PSModulePath. If you don't, then you need to solve that.

  • #10966
    Profile photo of Amandeep Bhatia
    Amandeep Bhatia
    Participant

    Hello,

    Thanks for the reply. May be i was not explicit in my last line of previous post for setting environment variable. I have set the environment variable manually from control panel.
    Now, When i run $env:PSModulePath in a new session of powershell I could see my path there.

    But not sure if that path is getting scanned or not, i dont see my modules being registered.
    I also tried adding export-modulemember -function

    Not sure what else i am missing.

You must be logged in to reply to this topic.