cinq2
cinq2

Reputation: 61

Powershell popup message on remote system closing after defined time

I like to be able to configure in my gui how much time will elapse before closing a popup message on remote cpu. I would like to have 2 options. Popup not close and popup close after x seconds. My $seconds parameter not work.

Function Send-PopupMessage1 {
Param(
[Int]$Seconds=""
)


Process{
Invoke-Command -ComputerName $cpu -Scriptblock {
    $CmdMessage = "msg.exe * $using:var2 /Time:$($Seconds)"
    Write-Host $CmdMessage
    $CmdMessage | Invoke-Expression
    }
}
}

if ($checkBox1.Checked)
{
Send-PopupMessage
}
else
{
Send-PopupMessage1 -Seconds $var1
}

This work better. Now its good.

Function Send-PopupMessage1 {
Param(
[String]$Message="$var",

[Parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
[Alias("Name")]
[String[]]$Computername=$var2,

[Int]$Seconds="$var1"
)


Process{
Invoke-Command -ComputerName $Computername -ScriptBlock{

    $cmd = "msg.exe * /Time:$($using:Seconds)"
    $cmd += " $($using:Message)"

    Invoke-Expression $cmd
    }
}
}

Upvotes: 0

Views: 207

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174555

Use the using qualifier that make $Seconds available inside the Invoke-Command block:

Invoke-Command -ComputerName $cpu -Scriptblock {
  $CmdMessage = "msg.exe * $using:var2 /Time:$($using:Seconds)"
  Write-Host $CmdMessage
  $CmdMessage | Invoke-Expression
}

Upvotes: 1

Related Questions