diff --git a/powershell/codeql-extractor.yml b/powershell/codeql-extractor.yml
index 43cd6f6dc959..eb7375f826dc 100644
--- a/powershell/codeql-extractor.yml
+++ b/powershell/codeql-extractor.yml
@@ -7,4 +7,11 @@ file_types:
- name: powershell
display_name: powershellscripts
extensions:
- - .ps1
\ No newline at end of file
+ - .ps1
+ - .psd1
+options:
+ skip_psmodulepath_files:
+ title: Skip PSModulePath files.
+ description: Whether to avoid extracting source files in paths specified by the PSModulePath environment variable.
+ type: string
+ pattern: "^(false|true)$"
\ No newline at end of file
diff --git a/powershell/extractor/Semmle.Extraction.PowerShell.Standalone/Options.cs b/powershell/extractor/Semmle.Extraction.PowerShell.Standalone/Options.cs
index 0b7c5075bebd..fa3b88fa1e07 100644
--- a/powershell/extractor/Semmle.Extraction.PowerShell.Standalone/Options.cs
+++ b/powershell/extractor/Semmle.Extraction.PowerShell.Standalone/Options.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -120,6 +121,24 @@ private static FileInfo[] GetDefaultFiles()
}
}
+ ///
+ /// Returns true if the extractor should skip files in the PSModulePath because the
+ /// environment variable CODEQL_EXTRACTOR_POWERSHELL_OPTION_SKIP_PSMODULEPATH_FILES
+ /// is set to a truthy value.
+ ///
+ private static bool GetDefaultSkipPSModulePathFiles()
+ {
+ var skip = System.Environment.GetEnvironmentVariable(
+ "CODEQL_EXTRACTOR_POWERSHELL_OPTION_SKIP_PSMODULEPATH_FILES"
+ );
+ bool b = skip != null && skip.ToLower() != "false";
+ if (b)
+ {
+ System.Console.WriteLine("Skipping files in PSModulePath");
+ }
+ return b;
+ }
+
///
/// The directory or file containing the source code;
///
@@ -134,7 +153,7 @@ private static FileInfo[] GetDefaultFiles()
/// Whether to extract files in the paths found in the `PSModulePath`
/// environment variable.
///
- public bool SkipPSModulePathFiles { get; private set; } = false;
+ public bool SkipPSModulePathFiles { get; private set; } = GetDefaultSkipPSModulePathFiles();
///
/// Whether errors were encountered parsing the arguments.
@@ -172,9 +191,13 @@ public static void ShowHelp(System.IO.TextWriter output)
" --exclude:xxx Exclude a file or directory (can be specified multiple times)"
);
output.WriteLine(" --dry-run Stop before extraction");
- output.WriteLine(" --threads:nnn Specify number of threads (default=CPU cores)");
+ output.WriteLine(
+ " --threads:nnn Specify number of threads (default=CPU cores)"
+ );
output.WriteLine(" --verbose Produce more output");
- output.WriteLine(" --skip-psmodulepath-files Avoid extracting source files in paths specified by the PSModulePath environment variable.");
+ output.WriteLine(
+ " --skip-psmodulepath-files Avoid extracting source files in paths specified by the PSModulePath environment variable."
+ );
}
private Options() { }
diff --git a/powershell/tools/qltest.cmd b/powershell/tools/qltest.cmd
index 0f129800d4b0..402978322d69 100644
--- a/powershell/tools/qltest.cmd
+++ b/powershell/tools/qltest.cmd
@@ -6,6 +6,7 @@ type NUL && "%CODEQL_DIST%\codeql.exe" database index-files ^
--size-limit=5m ^
--language=powershell ^
--working-dir=. ^
+ --extractor-option="powershell.skip_psmodulepath_files=true" ^
"%CODEQL_EXTRACTOR_POWERSHELL_WIP_DATABASE%"
exit /b %ERRORLEVEL%