wgross / fswatcher-engine-event

Publishes changes in file system as powershell engine event
MIT License
68 stars 11 forks source link

Can't run within a Job due to version check #12

Open randallt opened 2 months ago

randallt commented 2 months ago

I'm trying to run this as part of a job (just locally for now, but eventually remotely), but the minimum version check is failing.

Importing the module like this:

Import-Module FSWatcherEngineEvent

as part of the job fails with this message:

The current Windows PowerShell host is: 'ServerRemoteHost' (version 1.0.0.0). The module 'C:\Users\...\Documents\WindowsPowerShell\Modules\FSWatcherEngineEvent\1.5.0\FSWatcherEngineEvent.psd1' requires a minimum Windows PowerShell host version of '5.1' to run.
    + CategoryInfo          : ResourceUnavailable: (C:\Users\rtheob...ngineEvent.psd1:String) [Import-Module], InvalidOperationException
    + FullyQualifiedErrorId : Modules_InsufficientPowerShellHostVersion,Microsoft.PowerShell.Commands.ImportModuleCommand
    + PSComputerName        : localhost

If I import the module outside the job, I get a different error:

The 'New-FileSystemWatcher' command was found in the module 'FSWatcherEngineEvent', but the module could not be loaded. For more information, run 'Import-Module FSWatcherEngineEvent'.
    + CategoryInfo          : ObjectNotFound: (New-FileSystemWatcher:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
    + PSComputerName        : localhost

Is this because I only installed the module using scope "CurrentUser"? I'm on a CORP box and don't have admin privileges. I came across this thread on reddit, but I'm not sure if it is applicable. https://www.reddit.com/r/PowerShell/comments/s1fcvc/startjob_ps_version_inconsistency/

wgross commented 2 months ago

Hi @randallt, sorry for the late response, I was AFK for some days.

About the loading outside of the job: The module was found but couldn't be loaded. Please try to load the module using Import-Module FSWatcherEngineEvent -Verbose. This should give us more details why the module wasn't loading. If this doesn't work a job can't do it either.

About the version check in the remote host: I don't have an env currently to try this out. What you could try is to remove the version requirement in the module manifest FSWatcherEngineEvent.psd1': Comment the line PowershellHostVersion="5.1" out by adding # at the beginning or simply remove the line and try again. Maybe this helps with the remote host.

randallt commented 2 months ago

Sorry for not being clear. With regards to:

If I import the module outside the job, I get a different error

The import outside the job is successful, but trying to use it inside the job is where the error occurs.

To reiterate, I was not using a second/remote host here--just trying to use a PowerShell Job.