diff --git a/.github/workflows/build-test-ci.yml b/.github/workflows/build-test-ci.yml index 6694e02..8e9e356 100644 --- a/.github/workflows/build-test-ci.yml +++ b/.github/workflows/build-test-ci.yml @@ -30,8 +30,8 @@ jobs: - name: Dotnet Build & Publish run: | dotnet restore - dotnet build $env:Project_File -c Debug -f net8.0-windows -r win-${{ matrix.targetplatform }} --no-restore - dotnet publish $env:Project_File -c Debug -f net8.0-windows -r win-${{ matrix.targetplatform }} -o ./publish/FAFB_PowerShell_Tool_${{ matrix.targetplatform }} --no-restore + dotnet build $env:Project_File -c Debug -f net6.0-windows -r win-${{ matrix.targetplatform }} --no-restore + dotnet publish $env:Project_File -c Debug -f net6.0-windows -r win-${{ matrix.targetplatform }} -o ./publish/FAFB_PowerShell_Tool_${{ matrix.targetplatform }} --no-restore #- name: Upload Artifact # uses: actions/upload-artifact@v3 diff --git a/.github/workflows/release-ci.yml b/.github/workflows/release-ci.yml index 295c476..da144b8 100644 --- a/.github/workflows/release-ci.yml +++ b/.github/workflows/release-ci.yml @@ -30,8 +30,8 @@ jobs: - name: Dotnet Build & Publish run: | dotnet restore - dotnet build $env:Project_File -c Release -f net8.0-windows -r win-${{ matrix.targetplatform }} --no-restore - dotnet publish $env:Project_File -c Release -f net8.0-windows -r win-${{ matrix.targetplatform }} -o ./publish/FAFB_PowerShell_Tool_${{ matrix.targetplatform }} --no-restore + dotnet build $env:Project_File -c Release -f net6.0-windows -r win-${{ matrix.targetplatform }} --no-restore + dotnet publish $env:Project_File -c Release -f net6.0-windows -r win-${{ matrix.targetplatform }} -o ./publish/FAFB_PowerShell_Tool_${{ matrix.targetplatform }} --no-restore - name: Zip Release Files run: Compress-Archive -Path .\publish\FAFB_PowerShell_Tool_${{ matrix.targetplatform }} -DestinationPath .\FAFB_PowerShell_Tool_${{ matrix.targetplatform }}.zip diff --git a/.gitignore b/.gitignore index 0d608c1..e0bed98 100644 --- a/.gitignore +++ b/.gitignore @@ -479,3 +479,11 @@ $RECYCLE.BIN/ .vscode/launch.json .vscode/tasks.json + +.idea/.idea.FAFB-PowerShell-Tool/.idea/indexLayout.xml + +.idea/.idea.FAFB-PowerShell-Tool/.idea/workspace.xml + +FAFB-PowerShell-Tool/FAFB-PowerShell-Tool-Output.txt + +.idea/.idea.FAFB-PowerShell-Tool/.idea/ diff --git a/FAFB-PowerShell-Tool.Tests/GlobalUsings.cs b/FAFB-PowerShell-Tool.Tests/GlobalUsings.cs index ab67c7e..540383d 100644 --- a/FAFB-PowerShell-Tool.Tests/GlobalUsings.cs +++ b/FAFB-PowerShell-Tool.Tests/GlobalUsings.cs @@ -1 +1 @@ -global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file +global using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs b/FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs index 28deeea..cd3ad73 100644 --- a/FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs +++ b/FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs @@ -1,25 +1,20 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +namespace FAFB_PowerShell_Tool.Tests; -namespace FAFB_PowerShell_Tool.Tests +[TestClass] +public class PowerShellExecutorTest { - [TestClass] - public class PowerShellExecutorTest + private readonly PowerShellExecutor _powerShellExecutor = new(); + + [TestMethod] + public void ThrowArgumentNullExceptionWhenCommandTextIsNull() { - [TestMethod] - public void ThrowArgumentNullExceptionWhenCommandTextIsNull() - { - Assert.ThrowsException(() => PowerShellExecutor.Execute(null!)); - } + Assert.ThrowsException(() => _powerShellExecutor.Execute(null!)); + } - [TestMethod] - public void ThrowArgumentExceptionWhenCommandTextIsWhitespace() - { - Assert.ThrowsException(() => PowerShellExecutor.Execute("")); - Assert.ThrowsException(() => PowerShellExecutor.Execute(" ")); - } + [TestMethod] + public void ThrowArgumentExceptionWhenCommandTextIsWhitespace() + { + Assert.ThrowsException(() => _powerShellExecutor.Execute("")); + Assert.ThrowsException(() => _powerShellExecutor.Execute(" ")); } -} +} \ No newline at end of file diff --git a/FAFB-PowerShell-Tool/App.xaml.cs b/FAFB-PowerShell-Tool/App.xaml.cs index 2cd6839..b06bd4e 100644 --- a/FAFB-PowerShell-Tool/App.xaml.cs +++ b/FAFB-PowerShell-Tool/App.xaml.cs @@ -1,14 +1,9 @@ -using System.Configuration; -using System.Data; -using System.Windows; +using System.Windows; -namespace FAFB_PowerShell_Tool -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } +namespace FAFB_PowerShell_Tool; -} +/// +/// Interaction logic for App.xaml +/// +public partial class App : Application +{ } diff --git a/FAFB-PowerShell-Tool/AssemblyInfo.cs b/FAFB-PowerShell-Tool/AssemblyInfo.cs index b0ec827..020e92b 100644 --- a/FAFB-PowerShell-Tool/AssemblyInfo.cs +++ b/FAFB-PowerShell-Tool/AssemblyInfo.cs @@ -1,10 +1,9 @@ using System.Windows; -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] +[assembly:ThemeInfo(ResourceDictionaryLocation.None, // where theme specific resource dictionaries are located + // (used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly // where the generic resource dictionary is located + // (used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) + )] diff --git a/FAFB-PowerShell-Tool/Command.cs b/FAFB-PowerShell-Tool/Command.cs new file mode 100644 index 0000000..8acba74 --- /dev/null +++ b/FAFB-PowerShell-Tool/Command.cs @@ -0,0 +1,107 @@ +using System.Collections.ObjectModel; +using System.IO; +using System.Management.Automation; +using System.Windows; + +namespace FAFB_PowerShell_Tool; + +/// +/// This class is used to organize the all of the powershell commands +/// +/// +/// This is the root commands name ex. "get-aduser" +/// This is an array of the parameter options that the command has +/// This is the counr of the parameter array +public class Command +{ + public string CommandName { get; set; } + private string[] Parameters { get; set; } + private int ParameterCount { get; set; } + private static readonly PowerShellExecutor PowerShellExecutor = PowerShellExecutor; + + public Command(string commandName, string[] parameters, int parameterCount) + { + CommandName = commandName; + Parameters = parameters; + ParameterCount = parameterCount; + } + public Command(string commandName) + { + CommandName = commandName; + } + + /// + /// This is a method for getting a list of commands from a file + /// + /// "list" this is an ObservableCollection of the Commands + public static ObservableCollection ReadFileCommandList() + { + ObservableCollection list = new ObservableCollection(); + + try + { + // get the file path will probably want user input eventually and to use relative paths + string srcFilePath = + "C:\\Users\\pickl\\Source\\Repos\\FAFB-PowerShell-Tool\\FAFB-PowerShell-Tool\\commands.txt"; + string[] lines = File.ReadAllLines(srcFilePath); + + // Trim the strings and add them to the return list + foreach (string line in lines) + { + string trimmedLine = line.Trim(); + Command command = new Command(trimmedLine); + + list.Add(command); + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + + return list; + } + + /// + /// Retrieves the commands of a particular module. + /// + /// A List of Commands in an Observable Collection. + public static ObservableCollection GetPowerShellCommands() + { + return new ObservableCollection(); + } + + /// + /// Retrieves the parameters of a Command. + /// + /// The command in question. + /// ... + public static string[] GetParametersArray(Command c) + { + string getParameterSetNames = + "Import-Module ActiveDirectory" + "(Get-Command " + c.CommandName + + ").ParameterSets | Select-Object -Property @{n='ParameterSetName';e={$_.name}}, @{n='Parameters';e={$_.ToString()}}"; + + // List results = PowerShellExecutor.Execute(getParameterSetnames); + // Trace.WriteLine(results.Count); + + try + { + List commandOutput = PowerShellExecutor.Execute(getParameterSetNames); + string fullCommandOutput = ""; + + foreach (var str in commandOutput) + { + fullCommandOutput += str; + } + + MessageBoxOutput.ShowMessageBox(fullCommandOutput); + } + catch (Exception ex) + { + MessageBoxOutput.ShowMessageBox(ex.Message, MessageBoxOutput.OutputType.InternalError); + } + + return new string[1]; + } +} diff --git a/FAFB-PowerShell-Tool/FAFB-PowerShell-Tool.csproj b/FAFB-PowerShell-Tool/FAFB-PowerShell-Tool.csproj index 3662b9b..92a05c0 100644 --- a/FAFB-PowerShell-Tool/FAFB-PowerShell-Tool.csproj +++ b/FAFB-PowerShell-Tool/FAFB-PowerShell-Tool.csproj @@ -2,7 +2,7 @@ WinExe - net8.0-windows + net6.0-windows x64 FAFB_PowerShell_Tool enable @@ -18,8 +18,8 @@ - - + + diff --git a/FAFB-PowerShell-Tool/MainWindow.xaml b/FAFB-PowerShell-Tool/MainWindow.xaml index a969c2c..50e1b81 100644 --- a/FAFB-PowerShell-Tool/MainWindow.xaml +++ b/FAFB-PowerShell-Tool/MainWindow.xaml @@ -5,38 +5,83 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:FAFB_PowerShell_Tool" mc:Ignorable="d" - Title="Active Directory Queries" Height="450" Width="800"> + Title="MainWindow" Height="500" Width="800"> + + + + + + + + - - - + + + + + + + + + - + +