tj001
tj001

Reputation: 47

How to Show Message While Running PowerShell Script

I found below code to launch a scheduled task in Windows' 10 Task Scheduler. It spawns a PowerShell Window while the task is executing, and the task runs as expected. I expected to see the message "Waiting on scheduled task ..." displayed in the PowerShell window while the task was running. However, the message isn't displayed. How can I achieve that?

Start-ScheduledTask -TaskName "\FOLDER\TASK_NAME";

    while ((Get-ScheduledTask -TaskName 'TASK_NAME').State  -ne 'Ready') {

        Write-Verbose  -Message "Waiting on scheduled task..."

    }

Thank you.

Upvotes: 0

Views: 1032

Answers (1)

With PowerShell, it is easy to create an instance of a COM object. In our case, we need the Windows.Shell object from WSH. It can be created with the following command:

$wsh = New-Object -ComObject Wscript.Shell

Now, we can use our $wsh object to call methods available for Wscript.Shell. One of them is Popup, this is what we need. The following code can be used

$wsh = New-Object -ComObject Wscript.Shell

$wsh.Popup("Hello world")

read more

Upvotes: 0

Related Questions