private static Try <PendingRebootInfo> TryGetSccmClientRebootStatus() => () => { dynamic rebootStatus = F.RunPowerShell(new Some <Func <PowerShell, Collection <PSObject> > >(powerShell => powerShell .AddCommand("Invoke-WmiMethod") .AddParameter("NameSpace", @"root\ccm\ClientSDK") .AddParameter("Class", "CCM_ClientUtilities") .AddParameter("Name", "DetermineIfRebootPending") .Invoke()) ).FirstOrDefault(); var rebootIsPending = rebootStatus?.RebootPending || rebootStatus?.IsHardRebootPending; var rebootSource = rebootIsPending ? new List <RebootSource> { RebootSource.SccmClient } : new List <RebootSource>(); var pendingRebootInfo = new PendingRebootInfo { RebootIsPending = rebootIsPending, Sources = rebootSource }; Logging.DefaultLogger.Info($@"Sccm Client pending reboot check result: {pendingRebootInfo.ObjectToString()}"); return(new Result <PendingRebootInfo>(pendingRebootInfo)); };
private static async Task <Result <PendingRebootInfo> > GetCbsRebootPending() { var rebootPendingRegistryKeyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending"; Logging.DefaultLogger.Debug($@"Checking if Component Based Servicing has a pending reboot (Check if key exists: '{rebootPendingRegistryKeyPath}')."); var rebootIsPending = RegistryOperations.RegistryKeyExists(Registry.LocalMachine, rebootPendingRegistryKeyPath); var rebootSource = rebootIsPending ? new List <RebootSource> { RebootSource.Cbs } : new List <RebootSource>(); var pendingRebootInfo = new PendingRebootInfo { RebootIsPending = rebootIsPending, Sources = rebootSource }; Logging.DefaultLogger.Info($@"Component Based Servicing (CBS) pending reboot check result: {pendingRebootInfo.ObjectToString()}"); return(await Task.FromResult(new Result <PendingRebootInfo>(pendingRebootInfo)).ConfigureAwait(false)); }
private static async Task <Result <PendingRebootInfo> > GetPendingFileRenameRebootPending() { Logging.DefaultLogger.Debug($@"Checking if Pending File Rename Operations has a pending reboot."); var category = Profile.GetPolicyCategory(typeof(CheckPendingRebootCommand)); var pendingFileRenameOperationsSubCategory = category.Match(s => Option <string> .Some(s + "\\PendingFileRenameOperations"), Option <string> .None); var pendingFileRenameOperationsExcludePatternsSubCategory = pendingFileRenameOperationsSubCategory.Match(s => Option <string> .Some(s + "\\PendingFileRenameOperations\\ExcludePatterns"), Option <string> .None); var excludeRenameTargets = Profile.GetBooleanPolicyValue(Context.Machine, pendingFileRenameOperationsSubCategory, "ExcludeRenameTargets", false); var excludeDeleteTargets = Profile.GetBooleanPolicyValue(Context.Machine, pendingFileRenameOperationsSubCategory, "ExcludeDeleteTargets", false); var excludePatterns = Profile.GetBooleanPolicyValue(Context.Machine, pendingFileRenameOperationsSubCategory, "ExcludePatterns", false); var excludePatternsArray = excludePatterns ? Profile.GetPolicyStringValueNames(Context.Machine, pendingFileRenameOperationsExcludePatternsSubCategory).ToRegExPatterns().ToArray() : Array.Empty <Regex>(); var pendingFileRenameOperations = PendingFileRenameOperationExtensions.GetPendingFileRenameOperations() .Exclude(excludeRenameTargets, excludeDeleteTargets, excludePatternsArray) .Select(operation => operation.ToDto()) .ToArray(); Logging.DefaultLogger.Debug($"#Pending File Rename Operations: {pendingFileRenameOperations.Length}"); var rebootIsPending = pendingFileRenameOperations.Length > 0; var rebootSource = rebootIsPending ? new List <RebootSource> { RebootSource.PendingFileRenameOperations } : new List <RebootSource>(); var pendingRebootInfo = new PendingRebootInfo { RebootIsPending = rebootIsPending, Sources = rebootSource }; pendingRebootInfo.PendingFileRenameOperations.AddRange(pendingFileRenameOperations); Logging.DefaultLogger.Info($@"Pending file rename operation pending reboot check result: {pendingRebootInfo.ObjectToString()}"); return(await Task.FromResult(new Result <PendingRebootInfo>(pendingRebootInfo)).ConfigureAwait(false)); }