From d96a317bfa815f2a08a72f2626256e39eb5c2218 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 11 Jul 2024 23:54:12 -0700 Subject: [PATCH 1/8] Add empty input schema for RebootPending --- .../reboot_pending.dsc.resource.json | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/reboot_pending/reboot_pending.dsc.resource.json b/reboot_pending/reboot_pending.dsc.resource.json index 3f474f14c..065186d54 100644 --- a/reboot_pending/reboot_pending.dsc.resource.json +++ b/reboot_pending/reboot_pending.dsc.resource.json @@ -1,16 +1,22 @@ { - "$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json", - "description": "Returns info about pending reboot.", - "type": "Microsoft.Windows/RebootPending", - "version": "0.1.0", - "get": { - "executable": "powershell", - "args": [ - "-NoLogo", - "-NonInteractive", - "-NoProfile", - "-Command", - "reboot_pending.resource.ps1" - ] + "$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json", + "description": "Returns info about pending reboot.", + "type": "Microsoft.Windows/RebootPending", + "version": "0.1.0", + "get": { + "executable": "powershell", + "args": [ + "-NoLogo", + "-NonInteractive", + "-NoProfile", + "-Command", + "reboot_pending.resource.ps1" + ] + }, + "schema": { + "embedded": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "null" } + } } From 232316ebf559bde7e48f9580d1da60140a9735e6 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 11 Jul 2024 23:54:12 -0700 Subject: [PATCH 2/8] Add empty input schema for RebootPending --- .../reboot_pending.dsc.resource.json | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/reboot_pending/reboot_pending.dsc.resource.json b/reboot_pending/reboot_pending.dsc.resource.json index 3f474f14c..065186d54 100644 --- a/reboot_pending/reboot_pending.dsc.resource.json +++ b/reboot_pending/reboot_pending.dsc.resource.json @@ -1,16 +1,22 @@ { - "$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json", - "description": "Returns info about pending reboot.", - "type": "Microsoft.Windows/RebootPending", - "version": "0.1.0", - "get": { - "executable": "powershell", - "args": [ - "-NoLogo", - "-NonInteractive", - "-NoProfile", - "-Command", - "reboot_pending.resource.ps1" - ] + "$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json", + "description": "Returns info about pending reboot.", + "type": "Microsoft.Windows/RebootPending", + "version": "0.1.0", + "get": { + "executable": "powershell", + "args": [ + "-NoLogo", + "-NonInteractive", + "-NoProfile", + "-Command", + "reboot_pending.resource.ps1" + ] + }, + "schema": { + "embedded": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "null" } + } } From a8a25d2aa07dbcaf445ca517c0b628a8e362c5ca Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 12 Jul 2024 23:15:33 -0700 Subject: [PATCH 3/8] updated reboot_pending.dsc.resource.json --- reboot_pending/reboot_pending.dsc.resource.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/reboot_pending/reboot_pending.dsc.resource.json b/reboot_pending/reboot_pending.dsc.resource.json index 065186d54..c5e5b10cd 100644 --- a/reboot_pending/reboot_pending.dsc.resource.json +++ b/reboot_pending/reboot_pending.dsc.resource.json @@ -16,7 +16,12 @@ "schema": { "embedded": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "null" + "type": "null", + "properties": { + "RebootPending": { + "type": "boolean" + } + } } } } From 51adf7a9130b06709ba59ebcf2905b8e0d39e559 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 11 Jul 2024 23:54:12 -0700 Subject: [PATCH 4/8] Add empty input schema for RebootPending --- .../reboot_pending.dsc.resource.json | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/reboot_pending/reboot_pending.dsc.resource.json b/reboot_pending/reboot_pending.dsc.resource.json index 3f474f14c..065186d54 100644 --- a/reboot_pending/reboot_pending.dsc.resource.json +++ b/reboot_pending/reboot_pending.dsc.resource.json @@ -1,16 +1,22 @@ { - "$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json", - "description": "Returns info about pending reboot.", - "type": "Microsoft.Windows/RebootPending", - "version": "0.1.0", - "get": { - "executable": "powershell", - "args": [ - "-NoLogo", - "-NonInteractive", - "-NoProfile", - "-Command", - "reboot_pending.resource.ps1" - ] + "$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json", + "description": "Returns info about pending reboot.", + "type": "Microsoft.Windows/RebootPending", + "version": "0.1.0", + "get": { + "executable": "powershell", + "args": [ + "-NoLogo", + "-NonInteractive", + "-NoProfile", + "-Command", + "reboot_pending.resource.ps1" + ] + }, + "schema": { + "embedded": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "null" } + } } From 7c6d12aa8845eb604ba7d1c909a48c46d366ebb9 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 12 Jul 2024 23:15:33 -0700 Subject: [PATCH 5/8] updated reboot_pending.dsc.resource.json --- reboot_pending/reboot_pending.dsc.resource.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/reboot_pending/reboot_pending.dsc.resource.json b/reboot_pending/reboot_pending.dsc.resource.json index 065186d54..c5e5b10cd 100644 --- a/reboot_pending/reboot_pending.dsc.resource.json +++ b/reboot_pending/reboot_pending.dsc.resource.json @@ -16,7 +16,12 @@ "schema": { "embedded": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "null" + "type": "null", + "properties": { + "RebootPending": { + "type": "boolean" + } + } } } } From b6f315032619a19761863f9aacce22e06d093324 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 16 Jul 2024 13:21:10 -0700 Subject: [PATCH 6/8] Update reboot_pending/reboot_pending.dsc.resource.json Co-authored-by: Mikey Lombardi (He/Him) --- reboot_pending/reboot_pending.dsc.resource.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reboot_pending/reboot_pending.dsc.resource.json b/reboot_pending/reboot_pending.dsc.resource.json index c5e5b10cd..218f3399b 100644 --- a/reboot_pending/reboot_pending.dsc.resource.json +++ b/reboot_pending/reboot_pending.dsc.resource.json @@ -19,7 +19,8 @@ "type": "null", "properties": { "RebootPending": { - "type": "boolean" + "type": "boolean", + "readOnly": true } } } From 0777706147bf2088a9ce37f38b0c40086118833e Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 16 Jul 2024 13:28:04 -0700 Subject: [PATCH 7/8] updated pproperty to camelCasing --- reboot_pending/reboot_pending.dsc.resource.json | 4 ++-- reboot_pending/reboot_pending.resource.ps1 | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/reboot_pending/reboot_pending.dsc.resource.json b/reboot_pending/reboot_pending.dsc.resource.json index c5e5b10cd..20ea5dea2 100644 --- a/reboot_pending/reboot_pending.dsc.resource.json +++ b/reboot_pending/reboot_pending.dsc.resource.json @@ -16,9 +16,9 @@ "schema": { "embedded": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "null", + "type": "[object, null]", "properties": { - "RebootPending": { + "rebootPending": { "type": "boolean" } } diff --git a/reboot_pending/reboot_pending.resource.ps1 b/reboot_pending/reboot_pending.resource.ps1 index 24860b2a5..a64be69f8 100644 --- a/reboot_pending/reboot_pending.resource.ps1 +++ b/reboot_pending/reboot_pending.resource.ps1 @@ -1,13 +1,13 @@ # Reg keys are documented here: https://learn.microsoft.com/en-us/mem/configmgr/core/servers/deploy/install/list-of-prerequisite-checks#pending-system-restart - 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 } + 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 + return @{ rebootPending = $true } | ConvertTo-Json -Compress } }catch{} -return @{ RebootPending = $false } | ConvertTo-Json -Compress \ No newline at end of file +return @{ rebootPending = $false } | ConvertTo-Json -Compress \ No newline at end of file From b0ffd4d29edc55d36e6515d90c0f9373c0c348ef Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 26 Sep 2024 12:28:45 -0700 Subject: [PATCH 8/8] added tests for config --- reboot_pending/tests/reboot_pending.dsc.yaml | 4 ++++ reboot_pending/tests/reboot_pending.tests.ps1 | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 reboot_pending/tests/reboot_pending.dsc.yaml create mode 100644 reboot_pending/tests/reboot_pending.tests.ps1 diff --git a/reboot_pending/tests/reboot_pending.dsc.yaml b/reboot_pending/tests/reboot_pending.dsc.yaml new file mode 100644 index 000000000..2f7a9382a --- /dev/null +++ b/reboot_pending/tests/reboot_pending.dsc.yaml @@ -0,0 +1,4 @@ +$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json +resources: +- name: Pending reboot status + type: Microsoft.Windows/RebootPending diff --git a/reboot_pending/tests/reboot_pending.tests.ps1 b/reboot_pending/tests/reboot_pending.tests.ps1 new file mode 100644 index 000000000..087e21462 --- /dev/null +++ b/reboot_pending/tests/reboot_pending.tests.ps1 @@ -0,0 +1,17 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +Describe 'reboot_pending resource tests' { + It 'should get reboot_pending' -Skip:(!$IsWindows) { + $out = dsc resource get -r Microsoft.Windows/RebootPending | ConvertFrom-Json + $LASTEXITCODE | Should -Be 0 + $out.actualState.rebootPending | Should -Not -BeNullOrEmpty + } + + It 'reboot_pending works in a config' -Skip:(!$IsWindows) { + $ConfigPath = Resolve-Path "$PSScriptRoot/reboot_pending.dsc.yaml" + $out = dsc config get --path $ConfigPath | ConvertFrom-Json + $LASTEXITCODE | Should -Be 0 + $out.results.result.actualState.rebootPending | Should -Not -BeNullOrEmpty + } +}