Skip to content

Commit dca89d7

Browse files
authored
Feature: Improve PowerShell (function & design) (BornToBeRoot#1592)
* Feature: Improve PuTTY profile creation if Theme changes * Feature: Improve PowerShell / Add command
1 parent 4d24159 commit dca89d7

24 files changed

Lines changed: 218 additions & 35 deletions

Source/NETworkManager.Localization/Resources/Strings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/NETworkManager.Localization/Resources/Strings.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3227,4 +3227,7 @@ If not set, the default AWS CLI settings are used.</value>
32273227
<data name="SyncIsDisabled" xml:space="preserve">
32283228
<value>Synchronization is disabled!</value>
32293229
</data>
3230-
</root>
3230+
<data name="Command" xml:space="preserve">
3231+
<value>Command</value>
3232+
</data>
3233+
</root>

Source/NETworkManager.Models/PowerShell/PowerShell.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ public static string BuildCommandLine(PowerShellSessionInfo sessionInfo)
66
{
77
var command = $"-NoExit -ExecutionPolicy {sessionInfo.ExecutionPolicy} {sessionInfo.AdditionalCommandLine}";
88

9+
// Connect to remote host or execute local command if configured
910
if (sessionInfo.EnableRemoteConsole)
10-
command += $" -Command \"Enter-PSSession -ComputerName {sessionInfo.Host}\"";
11+
command += $" -Command \"& {{Enter-PSSession -ComputerName {sessionInfo.Host}}}\"";
12+
else if(!string.IsNullOrEmpty(sessionInfo.Command))
13+
command += $" -Command \"& {{{sessionInfo.Command}}}\"";
1114

1215
return command;
1316
}

Source/NETworkManager.Models/PowerShell/PowerShellSessionInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class PowerShellSessionInfo
77
public string ApplicationFilePath { get; set; }
88
public bool EnableRemoteConsole { get; set; }
99
public string Host { get; set; }
10+
public string Command { get; set; }
1011
public string AdditionalCommandLine { get; set; }
1112
public ExecutionPolicy ExecutionPolicy { get; set; }
1213

Source/NETworkManager.Profiles/Application/PowerShell.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static PowerShellSessionInfo CreateSessionInfo(ProfileInfo profile)
1515
EnableRemoteConsole = profile.PowerShell_EnableRemoteConsole,
1616
Host = profile.PowerShell_Host,
1717

18+
Command = profile.PowerShell_OverrideCommand ? profile.PowerShell_Command : (group.PowerShell_OverrideCommand ? group.PowerShell_Command : SettingsManager.Current.PowerShell_Command),
1819
AdditionalCommandLine = profile.PowerShell_OverrideAdditionalCommandLine ? profile.PowerShell_AdditionalCommandLine : (group.PowerShell_OverrideAdditionalCommandLine ? group.PowerShell_AdditionalCommandLine : SettingsManager.Current.PowerShell_AdditionalCommandLine),
1920
ExecutionPolicy = profile.PowerShell_OverrideExecutionPolicy ? profile.PowerShell_ExecutionPolicy : (group.PowerShell_OverrideExecutionPolicy ? group.PowerShell_ExecutionPolicy : SettingsManager.Current.PowerShell_ExecutionPolicy)
2021
};

Source/NETworkManager.Profiles/GroupInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public class GroupInfo
8282
public bool RemoteDesktop_OverrideVisualStyles { get; set; }
8383
public bool RemoteDesktop_VisualStyles { get; set; }
8484

85+
public bool PowerShell_OverrideCommand { get; set; }
86+
public string PowerShell_Command { get; set; }
8587
public bool PowerShell_OverrideAdditionalCommandLine { get; set; }
8688
public string PowerShell_AdditionalCommandLine { get; set; }
8789
public bool PowerShell_OverrideExecutionPolicy { get; set; }
@@ -195,6 +197,8 @@ public GroupInfo(GroupInfo group) : this(group.Name)
195197
RemoteDesktop_VisualStyles = group.RemoteDesktop_VisualStyles;
196198

197199
// PowerShell
200+
PowerShell_OverrideCommand = group.PowerShell_OverrideCommand;
201+
PowerShell_Command = group.PowerShell_Command;
198202
PowerShell_OverrideAdditionalCommandLine = group.PowerShell_OverrideAdditionalCommandLine;
199203
PowerShell_AdditionalCommandLine = group.PowerShell_AdditionalCommandLine;
200204
PowerShell_OverrideExecutionPolicy = group.PowerShell_OverrideExecutionPolicy;

Source/NETworkManager.Profiles/ProfileInfo.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using NETworkManager.Models.RemoteDesktop;
44
using NETworkManager.Settings;
55
using System.Security;
6-
using System.Security.RightsManagement;
76
using System.Xml.Serialization;
87

98
namespace NETworkManager.Profiles
@@ -136,6 +135,8 @@ public class ProfileInfo
136135
public bool PowerShell_EnableRemoteConsole { get; set; } = true;
137136
public bool PowerShell_InheritHost { get; set; } = true;
138137
public string PowerShell_Host { get; set; }
138+
public bool PowerShell_OverrideCommand { get; set; }
139+
public string PowerShell_Command { get; set; }
139140
public bool PowerShell_OverrideAdditionalCommandLine { get; set; }
140141
public string PowerShell_AdditionalCommandLine { get; set; }
141142
public bool PowerShell_OverrideExecutionPolicy { get; set; }
@@ -312,6 +313,8 @@ public ProfileInfo(ProfileInfo profile)
312313
PowerShell_EnableRemoteConsole = profile.PowerShell_EnableRemoteConsole;
313314
PowerShell_InheritHost = profile.PowerShell_InheritHost;
314315
PowerShell_Host = profile.PowerShell_Host;
316+
PowerShell_OverrideCommand = profile.PowerShell_OverrideCommand;
317+
PowerShell_Command = profile.PowerShell_Command;
315318
PowerShell_OverrideAdditionalCommandLine = profile.PowerShell_OverrideAdditionalCommandLine;
316319
PowerShell_AdditionalCommandLine = profile.PowerShell_AdditionalCommandLine;
317320
PowerShell_OverrideExecutionPolicy = profile.PowerShell_OverrideExecutionPolicy;

Source/NETworkManager.Settings/GlobalStaticConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public static class GlobalStaticConfiguration
119119

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

124125
// Application: PuTTY

Source/NETworkManager.Settings/SettingsInfo.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,21 @@ public string PowerShell_ApplicationFilePath
23752375
}
23762376
}
23772377

2378+
private string _powerShell_Command = GlobalStaticConfiguration.PowerShell_Command;
2379+
public string PowerShell_Command
2380+
{
2381+
get => _powerShell_Command;
2382+
set
2383+
{
2384+
if (value == _powerShell_Command)
2385+
return;
2386+
2387+
_powerShell_Command = value;
2388+
OnPropertyChanged();
2389+
SettingsChanged = true;
2390+
}
2391+
}
2392+
23782393
private string _powerShell_AdditionalCommandLine;
23792394
public string PowerShell_AdditionalCommandLine
23802395
{

Source/NETworkManager/Controls/AWSSessionManagerControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</UserControl.Resources>
1919
<Grid SizeChanged="WindowGrid_SizeChanged">
2020
<!-- Background color will prevent flickering when app inside the panel is closed -->
21-
<WindowsFormsHost Visibility="{Binding IsConnected, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" Background="{DynamicResource MahApps.Brushes.Window.Background}">
21+
<WindowsFormsHost Visibility="{Binding IsConnected, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" Background="{DynamicResource MahApps.Brushes.Window.Background}" Margin="10">
2222
<windowsForms:Panel x:Name="WindowHost" />
2323
</WindowsFormsHost>
2424
<Grid VerticalAlignment="Center" HorizontalAlignment="Center" TextBlock.TextAlignment="Center" Visibility="{Binding IsConnected, Converter={StaticResource BooleanReverseToVisibilityCollapsedConverter}}">

0 commit comments

Comments
 (0)