diff --git a/.github/workflows/dotnet-desktop-ci.yml b/.github/workflows/dotnet-desktop-ci.yml
index 3b6e2da..e57b58a 100644
--- a/.github/workflows/dotnet-desktop-ci.yml
+++ b/.github/workflows/dotnet-desktop-ci.yml
@@ -29,10 +29,10 @@ jobs:
dotnet-version: '8.0.x'
- name: Build
- run: dotnet build $env:Project_File -c Release -f net8.0-windows -r win-${{ matrix.targetplatform }} --self-contained true
+ run: dotnet build $env:Project_File -c Release -f net8.0-windows -r win-${{ matrix.targetplatform }}
- name: Publish Artifact
- run: dotnet publish -c Release -f net8.0-windows -r win-${{ matrix.targetplatform }} -o ./FAFB_PowerShell_Tool_${{ matrix.targetplatform }} --self-contained -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=embedded
+ run: dotnet publish -c Release -f net8.0-windows -r win-${{ matrix.targetplatform }} -o ./FAFB_PowerShell_Tool_${{ matrix.targetplatform }} --self-contained true -p:PublishSingleFile=false -p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=embedded
- name: Upload Artifact
uses: actions/upload-artifact@v3
diff --git a/FAFB-PowerShell-Tool.Tests/FAFB-PowerShell-Tool.Tests.csproj b/FAFB-PowerShell-Tool.Tests/FAFB-PowerShell-Tool.Tests.csproj
new file mode 100644
index 0000000..a3d96d5
--- /dev/null
+++ b/FAFB-PowerShell-Tool.Tests/FAFB-PowerShell-Tool.Tests.csproj
@@ -0,0 +1,24 @@
+
+
+
+ net8.0-windows
+ FAFB_PowerShell_Tool.Tests
+ enable
+ enable
+
+ false
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/FAFB-PowerShell-Tool.Tests/GlobalUsings.cs b/FAFB-PowerShell-Tool.Tests/GlobalUsings.cs
new file mode 100644
index 0000000..ab67c7e
--- /dev/null
+++ b/FAFB-PowerShell-Tool.Tests/GlobalUsings.cs
@@ -0,0 +1 @@
+global using Microsoft.VisualStudio.TestTools.UnitTesting;
\ No newline at end of file
diff --git a/FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs b/FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs
new file mode 100644
index 0000000..28deeea
--- /dev/null
+++ b/FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FAFB_PowerShell_Tool.Tests
+{
+ [TestClass]
+ public class PowerShellExecutorTest
+ {
+ [TestMethod]
+ public void ThrowArgumentNullExceptionWhenCommandTextIsNull()
+ {
+ Assert.ThrowsException(() => PowerShellExecutor.Execute(null!));
+ }
+
+ [TestMethod]
+ public void ThrowArgumentExceptionWhenCommandTextIsWhitespace()
+ {
+ Assert.ThrowsException(() => PowerShellExecutor.Execute(""));
+ Assert.ThrowsException(() => PowerShellExecutor.Execute(" "));
+ }
+ }
+}
diff --git a/FAFB-PowerShell-Tool.sln b/FAFB-PowerShell-Tool.sln
index e992312..411f4fa 100644
--- a/FAFB-PowerShell-Tool.sln
+++ b/FAFB-PowerShell-Tool.sln
@@ -1,10 +1,11 @@
-
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34309.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FAFB-PowerShell-Tool", "FAFB-PowerShell-Tool\FAFB-PowerShell-Tool.csproj", "{C6E51308-E9E0-4738-9D5A-49841912633B}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FAFB-PowerShell-Tool.Tests", "FAFB-PowerShell-Tool.Tests\FAFB-PowerShell-Tool.Tests.csproj", "{E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +40,26 @@ Global
{C6E51308-E9E0-4738-9D5A-49841912633B}.Release|x64.Build.0 = Release|Any CPU
{C6E51308-E9E0-4738-9D5A-49841912633B}.Release|x86.ActiveCfg = Release|Any CPU
{C6E51308-E9E0-4738-9D5A-49841912633B}.Release|x86.Build.0 = Release|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Debug|ARM.ActiveCfg = Debug|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Debug|ARM.Build.0 = Debug|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Debug|ARM64.ActiveCfg = Debug|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Debug|ARM64.Build.0 = Debug|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Debug|x64.Build.0 = Debug|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Debug|x86.Build.0 = Debug|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Release|ARM.ActiveCfg = Release|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Release|ARM.Build.0 = Release|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Release|ARM64.ActiveCfg = Release|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Release|ARM64.Build.0 = Release|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Release|x64.ActiveCfg = Release|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Release|x64.Build.0 = Release|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Release|x86.ActiveCfg = Release|Any CPU
+ {E93739C2-C7BC-4F69-BEA2-C5F30548EA8C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/FAFB-PowerShell-Tool/FAFB-PowerShell-Tool.csproj b/FAFB-PowerShell-Tool/FAFB-PowerShell-Tool.csproj
index 6c111f7..566eb29 100644
--- a/FAFB-PowerShell-Tool/FAFB-PowerShell-Tool.csproj
+++ b/FAFB-PowerShell-Tool/FAFB-PowerShell-Tool.csproj
@@ -8,10 +8,17 @@
enable
true
- true
+
+ false
true
embedded
- true
+ true
-
\ No newline at end of file
+
+
+
+
+
+
+
diff --git a/FAFB-PowerShell-Tool/MainWindow.xaml b/FAFB-PowerShell-Tool/MainWindow.xaml
index c20cd99..2c23aa0 100644
--- a/FAFB-PowerShell-Tool/MainWindow.xaml
+++ b/FAFB-PowerShell-Tool/MainWindow.xaml
@@ -5,8 +5,16 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FAFB_PowerShell_Tool"
mc:Ignorable="d"
- Title="MainWindow" Height="450" Width="800">
+ Title="Active Directory Queries" Height="450" Width="800">
+
+
+
+
+
+
+
+
diff --git a/FAFB-PowerShell-Tool/MainWindow.xaml.cs b/FAFB-PowerShell-Tool/MainWindow.xaml.cs
index 0fe82bc..dc2b86b 100644
--- a/FAFB-PowerShell-Tool/MainWindow.xaml.cs
+++ b/FAFB-PowerShell-Tool/MainWindow.xaml.cs
@@ -1,13 +1,5 @@
-using System.Text;
+using System.Diagnostics;
using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
namespace FAFB_PowerShell_Tool
{
@@ -16,9 +8,58 @@ namespace FAFB_PowerShell_Tool
///
public partial class MainWindow : Window
{
+ private string command = null!;
+
public MainWindow()
{
InitializeComponent();
}
+
+ private void CommandButton1(object sender, RoutedEventArgs e)
+ {
+ command = "Get-ADUser -filter * -Properties * | out-gridvie";
+ }
+
+ private void CommandButton2(object sender, RoutedEventArgs e)
+ {
+ command = "Get-Process | Out-String -Width 4096";
+ }
+
+ private void CommandButton3(object sender, RoutedEventArgs e)
+ {
+ command = "Get-ChildItem -Path $env:USERPROFILE | Out-String -Width 4096";
+ }
+
+ private void CommandButton4(object sender, RoutedEventArgs e)
+ {
+ command = "New-Item -Path $env:USERPROFILE\\myFile.txt -ItemType File";
+ }
+
+ private void ExecutionButton(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ List commandOutput = PowerShellExecutor.Execute(command);
+ string fullCommandOutput = "";
+
+
+ foreach (var str in commandOutput)
+ {
+ fullCommandOutput += str;
+ }
+
+ MessageBox.Show(fullCommandOutput);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("INTERNAL ERROR: " + ex.Message);
+ }
+ }
+
+ private void ExecuteGenericCommand(object sender, RoutedEventArgs e)
+ {
+ string hostName = System.Net.Dns.GetHostName();
+ MessageBox.Show("System Host Name: " + hostName);
+ }
}
}
\ No newline at end of file
diff --git a/FAFB-PowerShell-Tool/PowerShellExecutor.cs b/FAFB-PowerShell-Tool/PowerShellExecutor.cs
new file mode 100644
index 0000000..139a358
--- /dev/null
+++ b/FAFB-PowerShell-Tool/PowerShellExecutor.cs
@@ -0,0 +1,56 @@
+using System.Management.Automation;
+using System.Windows;
+
+namespace FAFB_PowerShell_Tool;
+
+// TODO: Should this be made into a singleton rather than a static class?
+public class PowerShellExecutor
+{
+ public static List Execute(string commandText)
+ {
+ using PowerShell ps = PowerShell.Create();
+ List returnValues = new List();
+
+ // TODO: Use a MessageBox to show errors to the user.
+ ThrowExceptionIfCommandTextIsNullOrWhiteSpace(commandText);
+ ps.AddScript(commandText);
+
+ var results = ps.Invoke();
+
+ if (ps.HadErrors)
+ {
+ foreach (var error in ps.Streams.Error)
+ {
+ returnValues.Add("Error: " + error.ToString());
+ }
+ }
+ else
+ {
+ foreach (var result in results)
+ {
+ returnValues.Add(result.ToString());
+ }
+ }
+
+ return returnValues;
+ }
+
+ private static void ThrowExceptionIfCommandTextIsNullOrWhiteSpace(string commandText)
+ {
+ if (commandText is null)
+ {
+ throw new ArgumentNullException("Command text cannot be null.");
+ }
+
+ if (string.IsNullOrWhiteSpace(commandText))
+ {
+ throw new ArgumentException("Command text cannot be null or whitespace.");
+ }
+ }
+
+ private static void ShowError(string message)
+ {
+ MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+}
+
diff --git a/README.md b/README.md
index 45e8a9d..8708856 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,3 @@
-# FAFB-PowerShell-Tool
\ No newline at end of file
+# FAFB-PowerShell-Tool
+
+[ADD DESCRIPTION OF PROJECT]