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.
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.