Need to add line for reboot

TechUST 516 Reputation points
2024-06-14T20:31:40.54+00:00

Hi,

I have a script that is working, but I need to add a line to restart the machine after 8 hours and it should give a notification as well. I will deploy this script using Intune through the Win32 method, so I also need to know what detection logic to apply.

#requires -runasadministrator Set-ExecutionPolicy Bypass -Scope Process -Force try { Get-CimInstance -Namespace root/WMI -ClassName Lenovo_SetBiosSetting | Invoke-CimMethod -MethodName SetBiosSetting -Arguments @{parameter = "UserPresenceSensing,Disable" } # If Supervisor Password is set, uncomment the line below and replace with your SVP. # Get-CimInstance -Namespace root/WMI -ClassName Lenovo_WmiOpcodeInterface | Invoke-CimMethod -MethodName WmiOpcodeInterface -Arguments @{Parameter = "WmiOpcodePasswordAdmin:supervisorpassword" } Get-CimInstance -Namespace root/WMI -ClassName Lenovo_SaveBiosSettings | Invoke-CimMethod -MethodName SaveBiosSettings Write-Output "User Presence Sensing Disabled." return 0 } catch { Write-Output $_.Exception.Message return 1 }

Microsoft System Center
Microsoft System Center
A suite of Microsoft systems management products that offer solutions for managing datacenter resources, private clouds, and client devices.
893 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
4,659 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,270 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Miguel Gonçalves | AVANADE 886 Reputation points
    2024-06-14T23:14:49.3033333+00:00

    Hi TechUST,

    Please use the shutdown command in Windows to schedule a restart. The /r switch is for restart, the /t switch specifies the time delay in seconds, and the /c switch is for the comment that will be shown in the notification.

    requires -runasadministrator

    restart the machine after 8 hours and show a notification before restarting

    Set-ExecutionPolicy Bypass -Scope Process -Force
    try {
        Get-CimInstance -Namespace root/WMI -ClassName Lenovo_SetBiosSetting | Invoke-CimMethod -MethodName SetBiosSetting -Arguments @{parameter = "UserPresenceSensing,Disable" }
    
        Get-CimInstance -Namespace root/WMI -ClassName Lenovo_SaveBiosSettings | Invoke-CimMethod -MethodName SaveBiosSettings
        Write-Output "User Presence Sensing is Disabled."
        
        shutdown.exe /r /t 28800 /c "System will restart in 8h"
        
        return 0
    } catch {
        Write-Output $_.Exception.Message
        return 1
    }
    

    # If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.