diff --git a/src/VirtualClient/VirtualClient.Actions.UnitTests/ScriptExecutor/PowershellExecutorTests.cs b/src/VirtualClient/VirtualClient.Actions.UnitTests/ScriptExecutor/PowershellExecutorTests.cs
index a91405cb53..10a8d6e158 100644
--- a/src/VirtualClient/VirtualClient.Actions.UnitTests/ScriptExecutor/PowershellExecutorTests.cs
+++ b/src/VirtualClient/VirtualClient.Actions.UnitTests/ScriptExecutor/PowershellExecutorTests.cs
@@ -132,21 +132,25 @@ public void SetupTest(PlatformID platform = PlatformID.Win32NT)
{ nameof(PowershellExecutor.CommandLine), "parameter1 parameter2" },
{ nameof(PowershellExecutor.ScriptPath), "genericScript.ps1" },
{ nameof(PowershellExecutor.LogPaths), "*.log;*.txt;*.json" },
- { nameof(PowershellExecutor.ToolName), "GenericTool" }
+ { nameof(PowershellExecutor.ToolName), "GenericTool" },
+ { nameof(PowershellExecutor.UsePwsh), false }
};
this.fixture.ProcessManager.OnCreateProcess = (command, arguments, directory) => this.fixture.Process;
}
[Test]
- [TestCase(PlatformID.Win32NT, @"\win-x64", @"genericScript.ps1", true)]
- [TestCase(PlatformID.Win32NT, @"\win-x64", @"genericScript.ps1", false)]
+ [TestCase(PlatformID.Win32NT, @"\win-x64", @"genericScript.ps1", true, false, "powershell")]
+ [TestCase(PlatformID.Win32NT, @"\win-x64", @"genericScript.ps1", false, false, "powershell")]
+ [TestCase(PlatformID.Win32NT, @"\win-x64", @"genericScript.ps1", true, true, "pwsh")]
+ [TestCase(PlatformID.Win32NT, @"\win-x64", @"genericScript.ps1", false, true, "pwsh")]
[Platform(Exclude = "Unix,Linux,MacOsX")]
- public async Task PowershellExecutorExecutesTheCorrectWorkloadCommands(PlatformID platform, string platformSpecificPath, string command, bool runElevated)
+ public async Task PowershellExecutorExecutesTheCorrectWorkloadCommands(PlatformID platform, string platformSpecificPath, string command, bool runElevated, bool usePwsh, string executorType)
{
this.SetupTest(platform);
this.fixture.Parameters[nameof(PowershellExecutor.RunElevated)] = runElevated;
this.fixture.Parameters[nameof(PowershellExecutor.ScriptPath)] = command;
+ this.fixture.Parameters[nameof(PowershellExecutor.UsePwsh)] = usePwsh;
string fullCommand = $"{this.mockPackage.Path}{platformSpecificPath}\\{command} parameter1 parameter2";
@@ -159,7 +163,7 @@ await executor.InitializeAsync(EventContext.None, CancellationToken.None)
string workingDirectory = executor.ExecutableDirectory;
- string expectedCommand = $"powershell -ExecutionPolicy Bypass -NoProfile -NonInteractive -WindowStyle Hidden -Command \"cd '{workingDirectory}';{fullCommand}\"";
+ string expectedCommand = $"{executorType} -ExecutionPolicy Bypass -NoProfile -NonInteractive -WindowStyle Hidden -Command \"cd '{workingDirectory}';{fullCommand}\"";
this.fixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDirectory) =>
{
if(expectedCommand == $"{exe} {arguments}")
diff --git a/src/VirtualClient/VirtualClient.Actions/ScriptExecutor/PowershellExecutor.cs b/src/VirtualClient/VirtualClient.Actions/ScriptExecutor/PowershellExecutor.cs
index bada79d781..464f2fed19 100644
--- a/src/VirtualClient/VirtualClient.Actions/ScriptExecutor/PowershellExecutor.cs
+++ b/src/VirtualClient/VirtualClient.Actions/ScriptExecutor/PowershellExecutor.cs
@@ -9,6 +9,7 @@ namespace VirtualClient.Actions
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using VirtualClient.Common;
+ using VirtualClient.Common.Extensions;
using VirtualClient.Common.Telemetry;
///
@@ -26,6 +27,17 @@ public PowershellExecutor(IServiceCollection dependencies, IDictionary
+ /// The parameter specifies whether to use pwsh, by default it is false
+ ///
+ public bool UsePwsh
+ {
+ get
+ {
+ return this.Parameters.GetValue(nameof(this.UsePwsh), false);
+ }
+ }
+
///
/// Executes the PowerShell script.
///
@@ -33,7 +45,7 @@ protected override async Task ExecuteAsync(EventContext telemetryContext, Cancel
{
using (BackgroundOperations profiling = BackgroundOperations.BeginProfiling(this, cancellationToken))
{
- string command = "powershell";
+ string command = this.UsePwsh ? "pwsh" : "powershell";
string commandArguments = SensitiveData.ObscureSecrets(
$"-ExecutionPolicy Bypass -NoProfile -NonInteractive -WindowStyle Hidden -Command \"cd '{this.ExecutableDirectory}';{this.ExecutablePath} {this.CommandLine}\"");
diff --git a/src/VirtualClient/VirtualClient.Contracts.UnitTests/VirtualClientComponentExtensionsTests.cs b/src/VirtualClient/VirtualClient.Contracts.UnitTests/VirtualClientComponentExtensionsTests.cs
index b96d7d2d0a..e64dc2db00 100644
--- a/src/VirtualClient/VirtualClient.Contracts.UnitTests/VirtualClientComponentExtensionsTests.cs
+++ b/src/VirtualClient/VirtualClient.Contracts.UnitTests/VirtualClientComponentExtensionsTests.cs
@@ -3,19 +3,20 @@
namespace VirtualClient.Contracts
{
+ using Microsoft.Extensions.DependencyInjection;
+ using Microsoft.Extensions.DependencyInjection.Extensions;
+ using Moq;
+ using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
+ using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.DependencyInjection.Extensions;
- using Moq;
- using NUnit.Framework;
using VirtualClient.Common.Contracts;
using VirtualClient.Common.Extensions;
using VirtualClient.Common.Telemetry;
@@ -252,7 +253,7 @@ public void CombineExtensionProducesTheExpectedPathOnUnixSystems()
}
[Test]
- public void CreateCreateFileUploadDescriptorsExtensionCreatesTheExpectedDescriptorsOnUnixSystems_1()
+ public void CreateFileUploadDescriptorsExtensionCreatesTheExpectedDescriptorsOnUnixSystems_1()
{
this.fixture.Setup(PlatformID.Unix);
@@ -297,7 +298,7 @@ public void CreateCreateFileUploadDescriptorsExtensionCreatesTheExpectedDescript
}
[Test]
- public void CreateCreateFileUploadDescriptorsExtensionCreatesTheExpectedDescriptorsOnUnixSystems_2()
+ public void CreateFileUploadDescriptorsExtensionCreatesTheExpectedDescriptorsOnUnixSystems_2()
{
this.fixture.Setup(PlatformID.Unix);
@@ -351,7 +352,8 @@ public void CreateCreateFileUploadDescriptorsExtensionCreatesTheExpectedDescript
}
[Test]
- public void CreateCreateFileUploadDescriptorsExtensionCreatesTheExpectedDescriptorsOnWindowsSystems_1()
+ [Platform(Include = "Win")]
+ public void CreateFileUploadDescriptorsExtensionCreatesTheExpectedDescriptorsOnWindowsSystems_1()
{
string directory = "C:\\Users\\User\\Logs";
string[] expectedFiles = new string[]
@@ -394,7 +396,8 @@ public void CreateCreateFileUploadDescriptorsExtensionCreatesTheExpectedDescript
}
[Test]
- public void CreateCreateFileUploadDescriptorsExtensionCreatesTheExpectedDescriptorsOnWindowsSystems_2()
+ [Platform(Include = "Win")]
+ public void CreateFileUploadDescriptorsExtensionCreatesTheExpectedDescriptorsOnWindowsSystems_2()
{
string directory = "C:\\Users\\User\\Logs";
string[] expectedFiles = new string[]
@@ -406,7 +409,7 @@ public void CreateCreateFileUploadDescriptorsExtensionCreatesTheExpectedDescript
this.fixture.FileSystem
.Setup(fs => fs.Path.GetDirectoryName(It.IsAny()))
- .Returns(file => file.Replace(Path.GetFileName(file), string.Empty));
+ .Returns(file => Path.GetDirectoryName(file));
this.fixture.FileSystem
.Setup(fs => fs.Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories))
diff --git a/website/docs/guides/0221-usage-extensions.md b/website/docs/guides/0221-usage-extensions.md
index 48986731f2..454bcc3d89 100644
--- a/website/docs/guides/0221-usage-extensions.md
+++ b/website/docs/guides/0221-usage-extensions.md
@@ -568,6 +568,7 @@ This component can be used to execute generic scripts using facilities common to
| PackageName | Name of the workload package built for running the script. If the workload package is being downloaded from blob package store, this needs to match with the package name defined in DependencyPackageInstallation. | String |
| FailFast | Flag indicates that the application should exit immediately on first/any errors regardless of their severity. | Boolean |
| UsePython3 | (Only valid for PythonExecutor) A true value indicates use of "python3" as environment variable to execute python, a false value will use "python" as the environment variable. | Boolean (Default is true) |
+ | UsePwsh | (Only valid for PowershellExecutor) A true value indicates use of "pwsh", a false value will use "powershell" as the command executor. | Boolean (Default is false) |
``` json
Example: