Skip to content

Commit 4f7a672

Browse files
authored
Feature: Use PWSH instead of Windows PowerShell (BornToBeRoot#1663)
* Feature: Use PWSH instead of Windows PowerShell * Docs: Add BornToBeRoot#1663
1 parent fdf35f9 commit 4f7a672

9 files changed

Lines changed: 42 additions & 9 deletions

File tree

Source/GlobalAssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[assembly: AssemblyConfiguration("")]
44
[assembly: AssemblyCompany("")]
5-
[assembly: AssemblyCopyright("Copyright © 2016-2021 BornToBeRoot")]
5+
[assembly: AssemblyCopyright("Copyright © 2016-2022 BornToBeRoot")]
66
[assembly: AssemblyTrademark("")]
77
[assembly: AssemblyCulture("")]
88

9-
[assembly: AssemblyVersion("2022.8.18.0")]
10-
[assembly: AssemblyFileVersion("2022.8.18.0")]
9+
[assembly: AssemblyVersion("2022.10.24.0")]
10+
[assembly: AssemblyFileVersion("2022.10.24.0")]

Source/NETworkManager.Models/PowerShell/PowerShell.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
using Microsoft.Win32;
22
using System;
33
using System.Collections.Generic;
4+
using System.IO;
45
using System.Linq;
56

67
namespace NETworkManager.Models.PowerShell
78
{
89
public static partial class PowerShell
910
{
1011

12+
public static readonly List<string> GetDefaultIntallationPaths = new()
13+
{
14+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "PowerShell", "7", "pwsh.exe"),
15+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "PowerShell", "7", "pwsh.exe"),
16+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"System32\WindowsPowerShell\v1.0\powershell.exe")
17+
};
18+
1119
/// <summary>
1220
/// Default SZ registry keys for the global PowerShell profile.
1321
/// </summary>

Source/NETworkManager.Models/PuTTY/PuTTY.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class PuTTY
2727
public static readonly List<string> GetDefaultInstallationPaths = new()
2828
{
2929
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), _puttyFolder, _puttyFile),
30-
Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.ProgramFilesX86), _puttyFolder, _puttyFile)
30+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), _puttyFolder, _puttyFile)
3131
};
3232

3333
/// <summary>

Source/NETworkManager.Settings/GlobalStaticConfiguration.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public static class GlobalStaticConfiguration
118118
public static NetworkConnectionType RemoteDesktop_NetworkConnectionType => NetworkConnectionType.DetectAutomatically;
119119

120120
// Application: PowerShell
121-
public static string PowerShell_ApplicationFileLocationPowerShell => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"System32\WindowsPowerShell\v1.0\powershell.exe");
122121
public static string PowerShell_Command => "Set-Location ~";
123122
public static PowerShell.ExecutionPolicy PowerShell_ExecutionPolicy => PowerShell.ExecutionPolicy.RemoteSigned;
124123

@@ -136,7 +135,6 @@ public static class GlobalStaticConfiguration
136135
public static int PuTTY_Raw => 0;
137136

138137
// Application: AWSSessionManager
139-
public static string AWSSessionManager_ApplicationFileLocationPowerShell => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"System32\WindowsPowerShell\v1.0\powershell.exe");
140138
public static bool AWSSessionManager_EnableSyncInstanceIDsFromAWS => false;
141139
public static bool AWSSessionManager_SyncOnlyRunningInstancesFromAWS => true;
142140

Source/NETworkManager.Settings/SettingsInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,7 +2377,7 @@ public ObservableCollection<string> PowerShell_HostHistory
23772377
}
23782378
}
23792379

2380-
private string _powerShell_ApplicationFilePath = GlobalStaticConfiguration.PowerShell_ApplicationFileLocationPowerShell;
2380+
private string _powerShell_ApplicationFilePath;
23812381
public string PowerShell_ApplicationFilePath
23822382
{
23832383
get => _powerShell_ApplicationFilePath;
@@ -2921,7 +2921,7 @@ public string AWSSessionManager_DefaultRegion
29212921
}
29222922
}
29232923

2924-
private string _awsSessionManager_ApplicationFilePath = GlobalStaticConfiguration.AWSSessionManager_ApplicationFileLocationPowerShell;
2924+
private string _awsSessionManager_ApplicationFilePath;
29252925
public string AWSSessionManager_ApplicationFilePath
29262926
{
29272927
get => _awsSessionManager_ApplicationFilePath;

Source/NETworkManager.Settings/SettingsManager.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using log4net;
22
using NETworkManager.Models;
3+
using NETworkManager.Models.PowerShell;
34
using System;
45
using System.IO;
56
using System.IO.Compression;
@@ -216,6 +217,19 @@ public static void Upgrade(Version fromVersion, Version toVersion)
216217

217218
_log.Info($"Add AWS Session Manager to application list...");
218219
Current.General_ApplicationList.Add(ApplicationManager.GetList().First(x => x.Name == ApplicationName.AWSSessionManager));
220+
221+
var powerShellPath = "";
222+
foreach(var file in PowerShell.GetDefaultIntallationPaths)
223+
{
224+
if(File.Exists(file))
225+
{
226+
powerShellPath = file;
227+
break;
228+
}
229+
}
230+
231+
_log.Info($"Set AWS Session Manager application file path to \"{powerShellPath}\"...");
232+
Current.AWSSessionManager_ApplicationFilePath = powerShellPath;
219233
}
220234

221235
// Set to latest version and save

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,17 @@ protected override async void OnContentRendered(EventArgs e)
422422
SettingsManager.Current.DNSLookup_DNSServers = new ObservableCollection<DNSServerInfo>(DNSServer.GetDefaultList());
423423
SettingsManager.Current.AWSSessionManager_AWSProfiles = new ObservableCollection<AWSProfileInfo>(AWSProfile.GetDefaultList());
424424

425+
// Check if PowerShell is installed
426+
foreach(var file in Models.PowerShell.PowerShell.GetDefaultIntallationPaths)
427+
{
428+
if(File.Exists(file))
429+
{
430+
SettingsManager.Current.PowerShell_ApplicationFilePath = file;
431+
SettingsManager.Current.AWSSessionManager_ApplicationFilePath = file;
432+
break;
433+
}
434+
}
435+
425436
// Check if PuTTY is installed
426437
foreach (var file in Models.PuTTY.PuTTY.GetDefaultInstallationPaths)
427438
{

docs/Changelog/next-release.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ permalink: /Changelog/next-release
2828
- Generate default lists at first run [#1544](https://github.com/BornToBeRoot/NETworkManager/pull/1544){:target="\_blank"}
2929
- Port Scanner
3030
- Add more port profiles (LDAP, HTTP proxy, Filetransfer) [#1526](https://github.com/BornToBeRoot/NETworkManager/pull/1526){:target="\_blank"}
31+
- PowerShell
32+
- Change default path on new installations to `pwsh.exe` (Windows PowerShell is used as fallback if `pwsh.exe` is not available) [#1663](https://github.com/BornToBeRoot/NETworkManager/pull/1663){:target="\_blank"}
3133
- PuTTY
3234
- Detect if PuTTY is installed at first run [#1542](https://github.com/BornToBeRoot/NETworkManager/pull/1542){:target="\_blank"}
3335
- Discovery Protocol

docs/Documentation/01_Application/12_AWSSessionManager.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ Path to the PowerShell console where the AWS CLI is available and which should b
337337

338338
**Type:** `String`
339339

340-
**Default:** `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`
340+
**Default:** `C:\Program Files\PowerShell\7\pwsh.exe`, `C:\Program Files (x86)\PowerShell\7\pwsh.exe` or `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`
341341

342342
**Possible values:**
343343

0 commit comments

Comments
 (0)