@LucD wrote:Why do you hae the /tmp folder in the PSModulePath variable?
That's something that only shows up when the script is called by the system, presumably it creates its own temporary space for that session in case it's needed.
The path when run as root is:
PS /root> Write-Output $Env:PSModulePath
/root/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/usr/bin/powershell/Modules
@LucD wrote:Not sure why you are doing the Save-Module part?
That should only be required when installing on a station that has no connection to the PSGallery.
Initially the modules were being installed in /root/.local/share/powershell/Modules and only available to root when run from the command line (or whatever other user installed the module). When run by the system even as root the same environment variable isn't used.
Pulling the module down with Save-Module then forcing it to install to /usr/bin/powershell/Modules made it available. Prior to this I installed it as per normal with just Install-Module however the PowerCLI commands were not available at all.
@LucD wrote:I would suggest to remove all PowerCLI related directories in all folders mentioned in PSModuePath.
Then do a fresh install with Install-Module.
Yep was how I initially had it but the module was not available to the system, hence the Save-Module. I've tried multiple fresh installs - they all work just fine when running the script directly or using the commands from a session, but they won't work when called by the system.