Pages

Thursday, 25 May 2023

PSADT to create Form sample

    $proceed = 'No'

   $noClickCounter = 0


    while ($proceed -ne 'Yes') {

    $proceed = Show-DialogBox -Title 'Installation Notice' -Text 'Application is Installed, would you like to restart the machine?' -Buttons $([System.Windows.Forms.MessageBoxButtons]::YesNo) -DefaultButton 'First' -Icon 'Exclamation' -Topmost $true


    if ($proceed -eq 'No') {

        $noClickCounter++


        if ($noClickCounter -eq 3) {

            $proceed = Show-DialogBox -Title 'Installation Notice' -Text 'Application is Installed, would you like to restart the machine?' -Buttons $([System.Windows.Forms.MessageBoxButtons]::OK) -DefaultButton 'First' -Icon 'Exclamation' -Topmost $true

        Restart-Computer -Force

        }

        else {

            Sleep -Seconds 30

        }

    }

    elseif ($proceed -eq 'Yes') {

        Restart-Computer -Force

    }

}


1 comment:

  1. $proceed = 'RestartLater'
    $noClickCounter = 0

    while ($noClickCounter -lt 3) {
    $noClickCounter++

    $proceed = Show-InstallationPrompt -Title 'Restart Prompt' -Message "OHS Application Installation Completed. Click 'RestartNow' To Reboot the Machine.Click 'RestartLater' to Snooze the Restart for 1 hour. Deferral $noClickCounter" -ButtonRightText 'Restartnow' -ButtonLeftText 'RestartLater'

    if ($proceed -eq 'RestartNow') {
    Restart-Computer -Force
    break
    }

    if ($noClickCounter -eq 3) {
    $proceed = Show-InstallationPrompt -Title 'Restart Prompt' -Message 'OHS Application Installation Completed. Maximum Restart Diferrals Completed.Restart your Machine Now' -ButtonMiddleText 'Restart'
    # Restart-Computer -Force
    }
    else {
    Sleep -Seconds 10
    }
    }

    ReplyDelete

User based detection

function getloggedindetails () {     ##Find logged in username     $user = Get-WmiObject Win32_Process - Filter "Name='explorer...

Search This Blog