DSInternals/Src/DSInternals.PowerShell/Commands/Encryption/ConvertFromGPPrefPasswordCommand.cs
2016-07-03 17:36:40 +02:00

46 lines
1.3 KiB
C#

namespace DSInternals.PowerShell.Commands
{
using System;
using System.Management.Automation;
using DSInternals.Common.Cryptography;
[Cmdlet(VerbsData.ConvertFrom, "GPPrefPassword")]
[OutputType(new Type[] { typeof(string) })]
public class ConvertFromGPPrefPasswordCommand : PSCmdlet
{
#region Parameters
[Parameter(
Mandatory = true,
Position = 0,
ValueFromPipeline = true,
HelpMessage = "Provide an encrypted password from a Group Policy Preferences XML file."
)]
public string EncryptedPassword
{
get;
set;
}
#endregion Parameters
#region Cmdlet Overrides
protected override void ProcessRecord()
{
WriteVerbose("Decrypting GP Preferences password.");
try
{
string password = GPPrefPwdObfuscator.Decrypt(EncryptedPassword);
this.WriteObject(password);
}
catch (Exception ex)
{
ErrorRecord error = new ErrorRecord(ex, "Error1", ErrorCategory.NotSpecified, EncryptedPassword);
this.WriteError(error);
}
}
#endregion Cmdlet Overrides
}
}