powershellwrapper icon indicating copy to clipboard operation
powershellwrapper copied to clipboard

Unable to use module from within a script

Open NeonBlueHDD opened this issue 5 years ago • 5 comments

Steps to reproduce

  1. Create blank powershell script

  2. Call "Import-Module ITGlueAPI" in script

  3. Call "Add-ITGlueApiKey" in script

Expected behavior

Run the command Add-ITGlueAPIKey

Actual behavior

Returns the error: "The term 'Add-ITGlueAPIKey' 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."

The script is being run by a windows service, and for whatever reason it cannot "see" those commands and I don't know why

Screenshots

N/A

Environment

Please share additional details about your environment. Version information for:

  • PowerShell
  • ITGlueAPI
  • Operating System

Environment command output: OsName : Microsoft Windows Server 2012 R2 Standard OsOperatingSystemSKU : StandardServerEdition OsArchitecture : 64-bit WindowsBuildLabEx : 9600.19812.amd64fre.winblue_ltsb_escrow.200814-1823 OsLanguage : en-US OsMuiLanguages : {en-US}

NeonBlueHDD avatar Sep 24 '20 20:09 NeonBlueHDD

Can you add Get-Module | Select -Property Name and see if the script sees ITGlueAPI in the list of modules? Second to that, run Get-Command -Module ITGlueAPI to see what commands are available?

I'm curious to see if the module is being seen. You may want to run $env:PSModulePath and check that the ITGlueAPI module contents are present in the folder path set as an environment variable.

CalebAlbers avatar Sep 25 '20 00:09 CalebAlbers

@CalebAlbers Thanks for the reply :).

I ran $env:PSModulePath, and it came back with C:\Program Files\WindowsPowerShell\Modules as one of the directories in the path, and that directory does contain the files for the ITGlueAPI powershell module.

As for the other test commands, I cannot get them to work in the script, but they work fine on my workstation. I ran the following commands on my workstation:

Get-Module | Select -Property Name >> C:\ModulesList.txt

Get-Command -Module ITGlueAPI >> C:\CommandsList.txt

The result is I have text files on my C: drive with the command output with info for the ITGlueAPI module visible. I pasted these exact same commands into the script, and the files that I get are completely blank. Am I doing something wrong, or is this also part of the problem?

NeonBlueHDD avatar Sep 25 '20 19:09 NeonBlueHDD

Did you run Get-Module on the server where you want to run the script and ensured that is installed there?

ecspresso avatar Sep 28 '20 06:09 ecspresso

Did you run Get-Module on the server where you want to run the script and ensured that is installed there?

Yes, I can confirm the module appears when I run Get-Module on the server that the script is running on. I can import the module and use the commands with no issues outside of the script, but the script itself cannot use any of the module commands at all after I import the module.

NeonBlueHDD avatar Sep 28 '20 13:09 NeonBlueHDD

@CalebAlbers @ecspresso Have there been any updates to this issue? Thanks so much :)

NeonBlueHDD avatar Oct 06 '20 17:10 NeonBlueHDD

I know this is two years old at this point, but I wonder if #131 fixes this - shipping imminently in v2.2.0

CalebAlbers avatar Dec 02 '22 07:12 CalebAlbers