Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random Issue in accessing Test-NetConnection inside a job #207

Open
RaghavendraP opened this issue Feb 15, 2020 · 3 comments
Open

Random Issue in accessing Test-NetConnection inside a job #207

RaghavendraP opened this issue Feb 15, 2020 · 3 comments

Comments

@RaghavendraP
Copy link

RaghavendraP commented Feb 15, 2020

I am using a Test-Netconnection function inside my RsJob. It works well most of the times but every now and then I get an error that says: "The 'Find-NetIPsecRule' command was found in the module 'NetSecurity', but the module could not be loaded. For more information, run 'Import-Module NetSecurity'. I am not sure why this happens only few times but not always if its a problem with module import.

By the way I was not using -ModulesToImport argument of RsJob to pass NetSecurity also I believe its not necessary as it works 95% of the times. But if that is needed, I can give it a try.

Full StackTrace:
Exception : System.Management.Automation.CommandNotFoundException: The 'Find-NetIPsecRule' command was found in
the module 'NetSecurity', but the module could not be loaded. For more information, run
'Import-Module NetSecurity'. ---> System.Management.Automation.CmdletInvocationException: Collection
was modified; enumeration operation may not execute. ---> System.InvalidOperationException:
Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List1.Enumerator.MoveNextRare() at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String moduleManifestPath, ExternalScriptInfo manifestScriptInfo, Hashtable data, Hashtable localizedData, ManifestProcessingFlags manifestProcessingFlags, Version minimumVersion, Version maximumVersion, Version requiredVersion, Nullable1 requiredModuleGuid, ImportModuleOptions& options, Boolean&
containedErrors)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String
fileName, String moduleBase, String prefix, SessionState ss, Object privateData,
ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found,
Boolean& moduleFileFound)
at
Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions
importModuleOptions, String name)
at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
--- End of inner exception stack trace ---
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean
performSyncInvoke)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.InvokeT
at System.Management.Automation.CommandDiscovery.AutoloadSpecifiedModule(String moduleName,
ExecutionContext context, SessionStateEntryVisibility visibility, Exception& exception)
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext
funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) at System.Management.Automation.PSScriptCmdlet.RunClause(Action1 clause, Object dollarUnderbar,
Object inputToProcess)
at System.Management.Automation.PSScriptCmdlet.DoProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
Message : The 'Find-NetIPsecRule' command was found in the module 'NetSecurity', but the module could not be
loaded. For more information, run 'Import-Module NetSecurity'.
FQID : CouldNotAutoloadMatchingModule,Test-NetConnection
InovcationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at ResolveNetworkSecurityDetails,
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\NetTCPIP\Test-NetConnection.psm1: line 343
at Test-NetConnection,
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\NetTCPIP\Test-NetConnection.psm1: line 615
at XXXXX, : line 261
at , : line 352
TargetObject : Find-NetIPsecRule

@MVKozlov
Copy link
Contributor

I briefly look at the Test-NetConnection code and seems it use Find-NetIPsecRule only when it run under UAC-raised admin
Please check it and if it is true, try to preload NetSecurity module because as far as I know nobody test nested module loading

@RaghavendraP
Copy link
Author

I've added the NetSecurity to ModulesToImport and will check if the problem is recurring or not. Thanks.

Also, found any reason why it would fail only few times but not always if this is the case? i create almost 100 jobs with a batch size of 25-30 and get this error only in 2-5 jobs and rest went through fine.

@MVKozlov
Copy link
Contributor

MVKozlov commented Feb 19, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants