Load PowerShell module on script execution. Add cmdlet to deserialize/decode variables.
parent
2282d9b013
commit
196feedded
|
@ -0,0 +1,24 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Management.Automation;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LANCommander.PowerShell.Cmdlets
|
||||||
|
{
|
||||||
|
[Cmdlet(VerbsData.ConvertFrom, "SerializedBase64")]
|
||||||
|
[OutputType(typeof(object))]
|
||||||
|
public class ConvertFromSerializedBase64Cmdlet : PSCmdlet
|
||||||
|
{
|
||||||
|
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||||
|
public string Input { get; set; }
|
||||||
|
|
||||||
|
protected override void ProcessRecord()
|
||||||
|
{
|
||||||
|
var xml = Encoding.UTF8.GetString(Convert.FromBase64String(Input));
|
||||||
|
|
||||||
|
WriteObject(PSSerializer.Deserialize(xml));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,6 +46,7 @@
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Cmdlets\ConvertFrom-SerializedBase64.cs" />
|
||||||
<Compile Include="Cmdlets\Edit-PatchBinary.cs" />
|
<Compile Include="Cmdlets\Edit-PatchBinary.cs" />
|
||||||
<Compile Include="Cmdlets\Uninstall-Game.cs" />
|
<Compile Include="Cmdlets\Uninstall-Game.cs" />
|
||||||
<Compile Include="Cmdlets\Install-Game.cs" />
|
<Compile Include="Cmdlets\Install-Game.cs" />
|
||||||
|
|
|
@ -18,18 +18,21 @@ namespace LANCommander.SDK.PowerShell
|
||||||
private bool IgnoreWow64 { get; set; } = false;
|
private bool IgnoreWow64 { get; set; } = false;
|
||||||
private ICollection<PowerShellVariable> Variables { get; set; }
|
private ICollection<PowerShellVariable> Variables { get; set; }
|
||||||
private Dictionary<string, string> Arguments { get; set; }
|
private Dictionary<string, string> Arguments { get; set; }
|
||||||
|
private List<string> Modules { get; set; }
|
||||||
private Process Process { get; set; }
|
private Process Process { get; set; }
|
||||||
|
|
||||||
public PowerShellScript()
|
public PowerShellScript()
|
||||||
{
|
{
|
||||||
Variables = new List<PowerShellVariable>();
|
Variables = new List<PowerShellVariable>();
|
||||||
Arguments = new Dictionary<string, string>();
|
Arguments = new Dictionary<string, string>();
|
||||||
|
Modules = new List<string>();
|
||||||
Process = new Process();
|
Process = new Process();
|
||||||
|
|
||||||
Process.StartInfo.FileName = "powershell.exe";
|
Process.StartInfo.FileName = "powershell.exe";
|
||||||
Process.StartInfo.RedirectStandardOutput = false;
|
Process.StartInfo.RedirectStandardOutput = false;
|
||||||
|
|
||||||
AddArgument("ExecutionPolicy", "Unrestricted");
|
AddArgument("ExecutionPolicy", "Unrestricted");
|
||||||
|
AddModule(Path.Combine(Environment.CurrentDirectory, "LANCommander.PowerShell.psd1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PowerShellScript UseFile(string path)
|
public PowerShellScript UseFile(string path)
|
||||||
|
@ -88,6 +91,13 @@ namespace LANCommander.SDK.PowerShell
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PowerShellScript AddModule(string path)
|
||||||
|
{
|
||||||
|
Modules.Add(path);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public PowerShellScript RunAsAdmin()
|
public PowerShellScript RunAsAdmin()
|
||||||
{
|
{
|
||||||
AsAdmin = true;
|
AsAdmin = true;
|
||||||
|
@ -111,9 +121,14 @@ namespace LANCommander.SDK.PowerShell
|
||||||
|
|
||||||
var wow64Value = IntPtr.Zero;
|
var wow64Value = IntPtr.Zero;
|
||||||
|
|
||||||
|
foreach (var module in Modules)
|
||||||
|
{
|
||||||
|
scriptBuilder.AppendLine($"Import-Module \"{module}\"");
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var variable in Variables)
|
foreach (var variable in Variables)
|
||||||
{
|
{
|
||||||
scriptBuilder.AppendLine($"${variable.Name} = Convert-FromSerializedBase64 \"{Serialize(variable.Value)}\"");
|
scriptBuilder.AppendLine($"${variable.Name} = ConvertFrom-SerializedBase64 \"{Serialize(variable.Value)}\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
scriptBuilder.AppendLine(Contents);
|
scriptBuilder.AppendLine(Contents);
|
||||||
|
|
Loading…
Reference in New Issue