Skip to content

Commit

Permalink
RebootPending resource
Browse files Browse the repository at this point in the history
  • Loading branch information
anmenaga committed Mar 4, 2024
1 parent 7a4b647 commit 5554766
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ $projects = @(
"tools/test_group_resource",
"y2j",
"wmi-adapter",
"resources/brew"
"resources/brew",
"reboot_pending"
)
$pedantic_unclean_projects = @("ntreg")
$clippy_unclean_projects = @("tree-sitter-dscexpression")
Expand Down
1 change: 1 addition & 0 deletions reboot_pending/copy_files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
reboot_pending.resource.ps1
16 changes: 16 additions & 0 deletions reboot_pending/reboot_pending.dsc.resource.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json",
"description": "Returns info about pending reboot.",
"type": "Microsoft/RebootPending",
"version": "0.1.0",
"get": {
"executable": "powershell",
"args": [
"-NoLogo",
"-NonInteractive",
"-NoProfile",
"-Command",
"reboot_pending.resource.ps1"
]
}
}
12 changes: 12 additions & 0 deletions reboot_pending/reboot_pending.resource.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return @{ RebootPending = $true } | ConvertTo-Json -Compress }
if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return @{ RebootPending = $true } | ConvertTo-Json -Compress }
if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return @{ RebootPending = $true } | ConvertTo-Json -Compress }
try {
$util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
$status = $util.DetermineIfRebootPending()
if(($status -ne $null) -and $status.RebootPending){
return @{ RebootPending = $true } | ConvertTo-Json -Compress
}
}catch{}

return @{ RebootPending = $false } | ConvertTo-Json -Compress

0 comments on commit 5554766

Please sign in to comment.