Skip to main content

For those of you having reboot issues - is the Predictable Reboot Notifications Worklet helping?


Show first post

29 replies

Forum|alt.badge.img
  • Novice
  • 28 replies
  • March 3, 2021

Only the changes i made for this is the “message to the sender”…


$execute = “C:\Windows\System32\msg.exe”

$message = “We have patched a security updates on your devices. Please reboot your workstation to take effect.”


$time = (Get-Date).AddSeconds(30)

$triggerAt = New-ScheduledTaskTrigger -At $time -Once

$currentusr = (Get-WmiObject -class win32_process -ComputerName ‘localhost’ | Where-Object name -Match explorer).getowner().user

$argument = $currentusr + " " + “/W” + " " + $message

$command = $execute + " " + $argument + " " + “| Out-Null `n”


New-Item -Path “c:\ProgramData\Amagent” -Name “message.ps1” -ItemType “file” -Value $command

Add-Content -Path “c:\ProgramData\Amagent\message.ps1” -Value “Restart-Computer”


$action = New-ScheduledTaskAction -Execute Powershell.exe -Argument “-windowstyle hidden c:\ProgramData\Amagent\message.ps1”


Register-ScheduledTask -TaskName “StartMsg” -Trigger $triggerAt -Action $action -User $currentusr

Start-Sleep 31

Unregister-ScheduledTask -TaskName “StartMsg” -Confirm:$false

#Remove-Item -Path “c:\ProgramData\Amagent\message.ps1”


Nic-Automox
  • Author
  • Former Automox Employee
  • 832 replies
  • March 3, 2021

Let’s check and see what the $currentusr variable is returning when it’s run through the worklet. Add this line:


Write-Output $currentusr


right after the $currentusr gets populated with the Get-WmiObject command.


Run the worklet again and look in the Activity Log report to see if “Greenlots IT” is showing just once, or twice.


Forum|alt.badge.img
  • Novice
  • 28 replies
  • March 3, 2021

Still showing twice. I will try to delete the worklet and create a new worklet and just paste the original code. Will see what happen.


Nic-Automox
  • Author
  • Former Automox Employee
  • 832 replies
  • March 3, 2021

Sounds good. I’m still not sure why the command returns one copy of the user when run manually, and then two when it’s run through the worklet. It could be that running it as System is the issue. The other thing you can try is running just the


(Get-WmiObject -class win32_process -ComputerName 'localhost' | Where-Object name -Match explorer).getowner().user


manually as the System user instead of the currently logged in user.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings