Skip to content

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

Description

@RaghavendraP

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions