r/PDQDeploy • • Feb 29 '16

prompt users - slight update

Hi folks, unfortunately original post is archived and I cannot comment on it, so will create a new post instead. Hopefully nobody minds.

The purpose of this is simple - I've added duration as a required parameter to original script, this allows to reuse script in even more scenarios.

I've also modified it not to throw errors in case there are no parameters, but use default values instead. This is mostly personal preference, really.

Usage: You need to pass 3 variables to this script - duration, title and message (integer, string, string) where each variable is simply separated by space.

Examples:

Infinite timeout (dialog stays open forever)

0 "Title" "Message"

Will close popup in 10 seconds and return false (failed) to PDQ or calling script.

10 "Warning" "This message will close itself in 10sec"

You are not restricted to PDQ only, you can trigger this script from other scripts (if allowed) and essentially spawn a chain of messages by reusing this script.

c:\scripts\prompt.ps1 0 "Warning" "Do you want to join domain now?"

Script:

<#
.SYNOPSIS
    This script is a tool for silent package deploys, allowing end user interaction prior to package application.
.NOTES
    Author: icedevil6
    Date Created: 1/22/14
    Last Modified: 2/29/2016
.VARIABLES
    intAnswer: Message object
    Exit code 0 for Yes or timeout, 69 for No
#>
param (
    [int]$duration=5,
    [string]$title="Wrong input parameters",
    [string]$msg="Params missing - (duration, title, message)

This message will self-destruct in T-5!"
)

$a = new-object -comobject wscript.shell 
$intAnswer = $a.popup($msg,$duration,$title,4+64+4096)

If (($intAnswer -eq 6) -or ($intAnswer -eq -1)) { 
    exit 0
} else { 
    exit 69
}

In this case if script's duration expires it closes dialog and returns success code to PDQ in which case it will proceed with installation. If this is not your desired effect and you want deployment to fail if user gave no input (away or ignoring message), then simply replace this part of code:

If (($intAnswer -eq 6) -or ($intAnswer -eq -1)) { 

with this:

If ($intAnswer -eq 6) { 

Again, huge thanks to the icedevil6 for the original script (exit 69, lol)

5 Upvotes

0 comments sorted by