1

I have to create a Powershell script and push the result to Nagios. My company have a module named "libNRDP.ps1" which have a cmdlet Update-NRDPServiceStatus.

The first line of my script (after some comments) is Import-Module ".\libNRDP.ps1". The most of the time, the script work properly but sometimes, for unknown reason the following error occures :

Update-NRDPServiceStatus : Le terme «Update-NRDPServiceStatus» n'est pas reconnu
comme nom d'applet de commande, fonction, fichier de script ou programme exécutable.
Vérifiez l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le
chemin d'accès est correct et réessayez.

And if I try to translate :

Update-NRDPServiceStatus : The term «Update-NRDPServiceStatus» is not reconized as cmdlet,
function, script file or executable program. Please check file name, path [...].

I never had an error while the Import-Module cmdlet is processing. So, I do not understand why this AEJMZEF script isn't working ! Thanks in advance.

1
  • 6
    You should use . .\libNRDP.ps1 to "dot-source" your script in order to load its definitions. While Import-Module seemingly also works (but apparently not always), it is meant to be used with actual modules (*.psm1), not regular scripts (*.ps1). Commented Nov 26, 2019 at 9:38

1 Answer 1

1

According to @mklement0 comment, the greate method is to "dot-source" the module.

I have replaced Import-Module ".\libNRDP.ps1" by . .\libNRDP.ps1 to execute the library in same scope as my script.

I think there is no more problems but since the "bug" does not appear each times, I cant affirm at 100% the solution is done.

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

1 Comment

This actually saved me from a lot of hassle, thanks. It's the only working way to import a simple class, for a beginner like me.

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.