Just some advise here as a MSP although we do not use the Dell program and we use a different one, I have found that the way they format/pass the commands/scripts for PowerShell don’t always correctly especially when there is a lot of broken down code and steps that you have so it might be worth also seeking Dell appliance help as they may have a better way of sending the code from the platform.
I totally agree with you on that. Thank you!
I have tested both of your script and it worked. Here is the combined final script. I choosed the first one (Olaf one).
#Based on <http://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542>
function Test-RebootRequired
{
$result = @{
CBSRebootPending =$false
WindowsUpdateRebootRequired = $false
FileRenamePending = $false
}
#Check CBS Registry
$key = Get-ChildItem "HKLM:Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -ErrorAction SilentlyContinue
if ($key -ne $null)
{
$result.CBSRebootPending = $true
}
#Check Windows Update
$key = Get-Item "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -ErrorAction SilentlyContinue
if($key -ne $null)
{
$result.WindowsUpdateRebootRequired = $true
}
#Check PendingFileRenameOperations
$prop = Get-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -ErrorAction SilentlyContinue
if($prop -ne $null)
{
$result.FileRenamePending = $true }
#Return Reboot required
return $result.ContainsValue($true)
}
#Now Check if there is no user logged in to reboot.
Function Get-LoggedInUser {
Get-Childitem -Path Registry::HKEY_USERS\ -ea 0 -exclude ".default" |
ForEach-Object { Get-ChildItem Registry::$_ } |
Where-Object { $_.Name -like "*Volatile Environment" } |
Get-ItemProperty -Name username |
ForEach-Object {
[PSCustomObject]@{
UserName = $_.Username
RegPath = $_.PSParentPath
FSPath = "$(Split-Path $env:public -Parent)\$($_.Username)"
}
}
}
if((Test-RebootRequired -eq "True") -and ((Get-LoggedInUser).UserName -eq $Null))
{
Write-Output 'No user logged in. Restarting the system'
shutdown -r -t 0 -d U:00:00
}
else{ return "False"}
Thank you Olaf, Doug, and Ben34 for your input, help and advice.
Levio.