Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 282 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I check for a pending reboot?

#1
I am trying to get to know where reboot is required or not for a Windows machine. However, my script is throwing and error.

powershell "$key = Get-Item "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -ErrorAction SilentlyContinue"

Error :
Get-Item : A positional parameter cannot be found that accepts argument
'Update\RebootRequired'.
At line:1 char:8
+ $key = Get-Item
HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Aut ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Item], ParameterBindin
gException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
.Commands.GetItemCommand

I am running this command in "command prompt". Not sure what it means !
Reply

#2

Your syntax wasn't correct, if you want to run the PowerShell command from cmd, it has to look like this:

powershell.exe "Get-Item 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired'"

But like Mathis mentioned, this key only exists if a reboot is pending.
Reply

#3
Pending reboot can be caused by variety of reasons, not just the ones that are detailed in other answers. Try [PendingReboot][1] module, which incorporates various tests into a single cmdlet:

# Install
Install-Module -Name PendingReboot

# Run
Test-PendingReboot -Detailed


[1]:

[To see links please register here]

Reply

#4
One thing I found that was causing this (and no end of headaches for me) was every time I tried to run the SCCM 1906 update it failed due to a pending reboot. Using this script in my investigations, I noticed it was ComponentBasedServicing that seemed to be holding up the works, which was the Optional Components were automatically installing. A little bit more digging lead me to a scheduled task called LanguageComponentsInstaller. I disabled this and I'm keeping an eye on it but it seems to have fixed this problem.

Thanks for the script. It's saved me a lot of stress trying to crack this egg :)
Reply

#5
You need to check 2 paths, one key and you need to query the configuration manager via `WMI` in order to check all possible locations.

```
#Adapted from
#Based on <http://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542>
function Test-PendingReboot {
if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return $true }
if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return $true }
if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true }
try {
$util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
$status = $util.DetermineIfRebootPending()
if (($status -ne $null) -and $status.RebootPending) {
return $true
}
}
catch { }

return $false
}

Test-PendingReboot
```
Reply

#6
(I would have preferred to add this as a comment on the accepted answer, but the code would not have fit.)

I think the following function can eliminate some unnecessary reboots. The `PendingFileRenameOperations` registry key supports not only renames, but also deletes (expressed essentially as "rename to null")<sup>*</sup>. The assumption I am making is that deletes represent pending cleanup operations that will not affect functionality in the meantime.

```
<#
.SYNOPSIS
Returns true if any true renames-- deletes are ignored-- are present in the
PendingFileRenameOperations registry key.
#>
function Test-PendingFileRename {
[OutputType('bool')]
[CmdletBinding()]
param()
$operations = (Get-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\').GetValue('PendingFileRenameOperations')
if ($null -eq $operations) {
$false
} else {
$trueOperationsCount = $operations.Length / 2
$trueRenames = [System.Collections.Generic.Dictionary[string, string]]::new($trueOperationsCount)
for ($i = 0; $i -ne $trueOperationsCount; $i++) {
$operationSource = $operations[$i * 2]
$operationDestination = $operations[$i * 2 + 1]
if ($operationDestination.Length -eq 0) {
Write-Verbose "Ignoring pending file delete '$operationSource'"
} else {
Write-Host "Found a true pending file rename (as opposed to delete). Source '$operationSource'; Dest '$operationDestination'"
$trueRenames[$operationSource] = $operationDestination
}
}
$trueRenames.Count -gt 0
}
}
```
One would implement this in the accepted answer's script by inserting the above function at the top and then replacing the line
```
if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true }
```
with
```
if (Test-PendingFileRename) { return $true }
```

<sup>*</sup> refs:
* [Interpreting the PendingFileRenameOperations Registry Key, J Jewitt](

[To see links please register here]

)
* [MoveFile Utility documentation, Microsoft](

[To see links please register here]

)
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through