0

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.

2
  • 3
    Are you running your script with the -Verbose flag ? If not, it might simply be runningn at a higher level. I would suggest you replace Write-Verbose by Write-Host and see what it does ? Commented Nov 16, 2022 at 22:04
  • 1
    Or add -Verbose at the end of Write-Verbose command Commented Nov 16, 2022 at 22:32

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.