How to programmatically write the current prompt line in Powershell

Can I send text to the current prompt line? Something like the following:

PS[10]> Get-Location
c:/
PS[11]> Write-PromptLine "This text has been written by Powershell"
PS[12]> This text has been written by Powershell|
# | denotes the caret
+3
source share
1 answer

You can use the SendKeys.SendWait method :

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait("This text has been written by Powershell")
+5
source

Source: https://habr.com/ru/post/1731348/


All Articles