static void Main(string[] args) { PSFactory myPowershell = new PSFactory(); if (myPowershell.openRunspace("dpfadmin", "Express10n!", "corpnet", "bil-corp12.corpnet.liox.org")) { // Start Basic and run a simple command in the runspace WriteResult(myPowershell.RunScript(new List <string> { "Get-Service", "Get-Host" })); // Now, lets try our AD Utilities Library // Return the BitLocker Recover Keys for a System IEnumerable <BitLocker_KeySet> computerKeys = Bitlocker.Get_ADBitLockerRecoveryKeys(myPowershell, "BAL-DF-E6500"); foreach (BitLocker_KeySet keySet in computerKeys) { Console.WriteLine("Date Created : {0}", keySet.KeyDate); Console.WriteLine("Machine ID : {0}", keySet.MachineID); Console.WriteLine("Recovery Key : {0}", keySet.RecoveryKey); } // Clean up Afterwards myPowershell.closeRunspace(); } ////; ////WriteResult(myPowershell.RunScript(new List<string> { "hostname | write-host" })); ////WriteResult(myPowershell.RunScript(new List<string> { "a=1+2" })); //myPowershell.closeRunspace(); }
public void Execute(IActivityRequest request, IActivityResponse response) { //response.WithFiltering().PublishRange(runCommand(request.Inputs["Computer Name"].AsString())); string strComputer = request.Inputs["Computer Name"].AsString(); PSFactory myPowershell = new PSFactory(); if (myPowershell.openRunspace(connection.UserName, connection.Password, connection.Domain, connection.Host)) { IEnumerable <BitLocker_KeySet> computerKeys = Bitlocker.Get_ADBitLockerRecoveryKeys(myPowershell, "BAL-DF-E6500"); int numKeys = response.WithFiltering().PublishRange(computerKeys); response.Publish("Number of Keys", numKeys); myPowershell.closeRunspace(); } }
public static IEnumerable <WU_RebootStatus> Get_RebootStatus(PSFactory psRunspace, string strComputer) { // Create a Dictionary to store the results List <Dictionary <string, string> > results; // Execute our Query results = psRunspace.RunScript(new List <string> { "New-Object -ComObject 'Microsoft.Update.SystemInfo'" }); foreach (var entry in results) { if (entry.ContainsKey("RebootRequired")) { string rebootRequired = entry["RebootRequired"]; yield return(new WU_RebootStatus(rebootRequired)); } } }
public static IEnumerable <BitLocker_KeySet> Get_ADBitLockerRecoveryKeys(PSFactory psRunspace, string strComputer) { // First Load up our Powershell Resources (Modules and Functions) string fileContent = Resources.Get_ADBitLockerRecoveryKeys; // Create a Dictionary to store the results List <Dictionary <string, string> > results; // Execute our Query results = psRunspace.RunScript(new List <string> { fileContent, "Get-BitLockerRecoveryKey -Computer " + strComputer }); foreach (var entry in results) { if (entry.ContainsKey("RecoveryPassword")) { string canonicalName = entry["CanonicalName"]; string recoveryPassword = entry["RecoveryPassword"]; yield return(new BitLocker_KeySet(canonicalName, recoveryPassword)); } } }
static void Main(string[] args) { PSFactory myPowershell = new PSFactory(); if (myPowershell.openRunspace("dpfadmin", "Express10n!", "corpnet", "bil-corp12.corpnet.liox.org")) { // Start Basic and run a simple command in the runspace WriteResult(myPowershell.RunScript(new List <string> { "Get-Service", "Get-Host" })); // Now, lets try our AD Utilities Library // Return the BitLocker Recover Keys for a System IEnumerable <WU_RebootStatus> rebootState = WU_Activities.Get_RebootStatus(myPowershell, "BAL-DF-E6500"); foreach (WU_RebootStatus computerRebootState in rebootState) { Console.WriteLine("Pending Reboot : {0}", computerRebootState.PendingReboot); } // Clean up Afterwards myPowershell.closeRunspace(); } }