I have made a function in a psm1-file.
To make it accessible by whoever runs PS, I put it in $PSHOME\Modules\<folder with the name of the PSM1-file>
My backup application can run CMD-files before and after the actual backup. I wanted my function to be used before backup, so I created a CMD-file to use the function in PowerShell.
If I start a CMD-window, and run the CMD-file it works fine, but not when launched from the backup program.
It does not matter if I start Powershell with "-ExecutionPolicy Bypass " as below, or not.
'D:\Backup-scripts>Powershell -ExecutionPolicy Bypass Remove-Oldest -Number 1 -Path """N:\My backups\My D on N partitions""" -Filter """*.tib""" -Reserv 3'
Error message:
Remove-Oldest : The term 'Remove-Oldest' 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.
At line:1 char:1
+ Remove-Oldest -Number 1 -Path "N:\My backups\My D on N partitions" -Filter "*.ti ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Remove-Oldest:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I use PowerShell 3, so when PS is loaded it should automatically load the psm1-file when the function in it is called. To be sure that the function is known I have also done "update-help -force". I don't know if that has any effect, but it could be some way for PS to get a list of installed modules, so I thought that could help PS to know what to load when the function is called.
The backup application is scheduled as run by the user Administrator.
Grateful for help :-)