diff --git a/Engine/Commands/InvokeScriptAnalyzerCommand.cs b/Engine/Commands/InvokeScriptAnalyzerCommand.cs index ae2e0858e..641ceae59 100644 --- a/Engine/Commands/InvokeScriptAnalyzerCommand.cs +++ b/Engine/Commands/InvokeScriptAnalyzerCommand.cs @@ -279,8 +279,9 @@ protected override void BeginProcessing() this.SessionState, recurseCustomRulePath); - if (IsFileParameterSet()) + if (IsFileParameterSet() && Path != null) { + // just used to obtain the directory to use to find settings below ProcessPath(); } @@ -350,6 +351,11 @@ protected override void ProcessRecord() return; } + if (IsFileParameterSet()) + { + ProcessPath(); + } + #if !PSV3 // TODO Support dependency resolution for analyzing script definitions if (saveDscDependency) diff --git a/Tests/Engine/CustomizedRule.tests.ps1 b/Tests/Engine/CustomizedRule.tests.ps1 index 2062f995a..753a82d05 100644 --- a/Tests/Engine/CustomizedRule.tests.ps1 +++ b/Tests/Engine/CustomizedRule.tests.ps1 @@ -9,7 +9,7 @@ if (-not (Test-PSEditionCoreCLR)) $null,"Wow6432Node" | ForEach-Object { try { - Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force + Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -ErrorAction SilentlyContinue } catch { @@ -66,7 +66,7 @@ Describe "Test importing correct customized rules" { $null,"Wow6432Node" | ForEach-Object { try { - Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force + Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -EA SilentlyContinue } catch { diff --git a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 index 049b0f682..c43cac665 100644 --- a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 +++ b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 @@ -180,7 +180,22 @@ Describe "Test Path" { Remove-PSDrive $freeDriveName $numFilesResult | Should -Be $numFilesExpected } - } + } + + Context "When piping in files" { + It "Can be piped in from a string" { + $piped = ("$directory\TestScript.ps1" | Invoke-ScriptAnalyzer) + $explicit = Invoke-ScriptAnalyzer -Path $directory\TestScript.ps1 + + $piped.Count | Should Be $explicit.Count + } + + It "Can be piped from Get-ChildItem" { + $piped = ( Get-ChildItem -Path $directory -Filter TestTestPath*.ps1 | Invoke-ScriptAnalyzer) + $explicit = Invoke-ScriptAnalyzer -Path $directory\TestTestPath*.ps1 + $piped.Count | Should Be $explicit.Count + } + } } Context "When given a directory" { diff --git a/Tests/Engine/LibraryUsage.tests.ps1 b/Tests/Engine/LibraryUsage.tests.ps1 index a33d4fa3f..47930561f 100644 --- a/Tests/Engine/LibraryUsage.tests.ps1 +++ b/Tests/Engine/LibraryUsage.tests.ps1 @@ -191,7 +191,7 @@ $testingLibraryUsage = $true $null,"Wow6432Node" | ForEach-Object { try { - Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force + Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -ErrorAction SilentlyContinue } catch {