Unable to use module from within a script
Steps to reproduce
-
Create blank powershell script
-
Call "Import-Module ITGlueAPI" in script
-
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}
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 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?
Did you run Get-Module on the server where you want to run the script and ensured that is installed there?
Did you run
Get-Moduleon 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.
@CalebAlbers @ecspresso Have there been any updates to this issue? Thanks so much :)
I know this is two years old at this point, but I wonder if #131 fixes this - shipping imminently in v2.2.0