Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use module from within a script #109

Closed
NeonBlueHDD opened this issue Sep 24, 2020 · 6 comments
Closed

Unable to use module from within a script #109

NeonBlueHDD opened this issue Sep 24, 2020 · 6 comments

Comments

@NeonBlueHDD
Copy link

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}

@CalebAlbers
Copy link
Contributor

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.

@NeonBlueHDD
Copy link
Author

NeonBlueHDD commented Sep 25, 2020

@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?

@ecspresso
Copy link
Contributor

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

@NeonBlueHDD
Copy link
Author

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
Copy link
Author

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

@CalebAlbers
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants