Rhonda
Rhonda

Reputation: 1721

pop-up doesn't display as expected when using function

I have a PowerShell script that displays a pop-up with title as "Final Report":

$c = new-object -comobject wscript.shell
$d = $c.popup("Report saved in " + $filename,0,"Final Report",1)

But when I create a function and invoke it to do the same thing:

function popUp($text,$title) {
    $a = new-object -comobject wscript.shell
    $b = $a.popup($text,0,$title,0)
}

popUp("Report saved in " + $filename,"Final Report")

The pop-up has a blank title, no "Final Report".

I know I'm using the correct syntax, based on http://ss64.com/vb/popup.html.

What is missing?

Upvotes: 0

Views: 116

Answers (1)

arco444
arco444

Reputation: 22821

Right syntax for the comobject popup, but not for calling a PowerShell function!

You need a space between the arguments:

function popUp($text,$title){
    $a = new-object -comobject wscript.shell
    $b = $a.popup($text,0,$title,0)
}

popUp "Report saved in $filename" "Final Report"

If you use a comma, it treats it as one argument to the function where that argument will be an array.

Upvotes: 2

Related Questions