PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.87k stars 379 forks source link

"Invoke-ScriptAnalyzer : The network path was not found" run time error thrown by PSSA #1771

Open hankyi95 opened 2 years ago

hankyi95 commented 2 years ago

We are using PSSA as a PR policy for our repo, when the ps1 file has a code like this:

& "\\networkpath\\test.exe" 

The Invoke-ScriptAnalyzer will throw a error like "Invoke-ScriptAnalyzer : The network path was not found" The error will disappear if I change the code like this

$path = "\\networkpath\\test.exe" 
& $path

I think PSSA should not check the networkpath, since .ps1 file will be running on a different environment other than dev environment. Also, this check seems not a rule in PSSA, but it caused a runtime error when calling Invoke-ScriptAnalyzer and this break our PR policy pipeline. Should PSSA not throw the error in such condition?

bergmeister commented 2 years ago

@hankyi95 I cannot reproduce using the latest version with Invoke-ScriptAnalyzer -ScriptDefinition '& "\\networkpath\\test.exe"' Can you please provide more details around version of PSScriptAnalyzer, PowerShell, OS, etc. Also, does it matter if the file exists or not?

hankyi95 commented 2 years ago

PSScriptAnalyzer Version: 1.20.0 Powershell Version: 5.1.19041.1320 OS Version: Win10

The file does not matter. I dont' have such file. But the "Access to the networkpath" matters. If change the code to

&"\\{networkpath can access}\\test.exe"

No error will report.

bergmeister commented 2 years ago

Thanks for the info. Still cannot reproduce. To test, I created a local share from a local folder so that the path starts with \{hostname}... and also used the PowerShell version that you reported

bergmeister commented 2 years ago

Please provide more details of the error by running this command right after the error gets thrown: $error[0] | Select-Object *

hankyi95 commented 2 years ago

Sorry for the late reply. Here is the error detail

writeErrorStream : True PSMessageDetails : Exception : System.Management.Automation.CmdletInvocationException: The network path was not found ---> System.IO.IOException: The network path was not found ---> System.ComponentModel.Win32Exception: The network path was not found --- End of inner exception stack trace --- at System.Management.Automation.Utils.NativeFileExists(String path) at System.Management.Automation.CommandSearcher.GetInfoFromPath(String path) at System.Management.Automation.CommandSearcher.ProcessPathSearchState() at System.Management.Automation.CommandSearcher.MoveNext() at Microsoft.PowerShell.Commands.GetCommandCommand.FindCommandForName(SearchResolutionOptions options, String commandName, Boolean isPattern, Boolean emitErrors, Int32& currentCount, Boolean& isDuplicate) at Microsoft.PowerShell.Commands.GetCommandCommand.AccumulateMatchingCommands(IEnumerable1 commandNames) 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.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync) 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.Invoke[T]() at Microsoft.Windows.PowerShell.ScriptAnalyzer.CommandInfoCache.GetCommandInfoInternal(String cmdName, Nullable1 commandType) at System.Lazy1.CreateValue() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Lazy1.LazyInitValue() at Microsoft.Windows.PowerShell.ScriptAnalyzer.CommandInfoCache.GetCommandInfo(String commandName, Nullable1 commandTypes, Boolean bypassCache) at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseShouldProcessCorrectly.Suppor tsShouldProcess(String cmdName) at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseShouldProcessCorrectly.CheckF orSupportShouldProcess() at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseShouldProcessCorrectly.<Analy zeScript>d__7.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass83_1.<Analyze SyntaxTree>b__2() TargetObject : CategoryInfo : InvalidOperation: (:) [Invoke-ScriptAnalyzer], CmdletInvocationException FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand ErrorDetails : InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at , : line 1 PipelineIterationInfo : {0, 1}

ghost commented 2 years ago

Closing due to inactivity

ghost commented 2 years ago

Closing due to inactivity

ghost commented 2 years ago

Closing due to inactivity

ghost commented 2 years ago

Closing due to inactivity