Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

I struggled with this and found many overly complicated posts.

It was hard to debug since I couldn't use "write-host" as it was a background job, so I used notepad to test like so:

Note: open a notepad "untitled document" and then watch PowerShell type in variable

function Do-StartJobWithArgs {
    Start-Job -ScriptBlock {
     Param($ArgVal)
     Sleep 1
     $wshell = New-Object -ComObject wscript.shell
     $wshell.AppActivate("Untitled - Notepad")
     sleep 1
     $wshell.SendKeys($ArgVal)
     sleep 1
    } -ArgumentList @($ArgVal)
}
$ArgVal = "TESTING"
Do-StartJobWithArgs
  • No labels