PowerShell - respond to command response

I am trying to write a simple script that will execute a console command on Windows that will always ask for confirmation to overwrite existing data. I thought something like below would work, but it seems like I was wrong (and not surprisingly, write-host does not interact with the command line, I believe that it just puts the text on the screen). Can anyone give some advice on how to handle this? I need to be able to run the script scheduler through the task scheduler weekly without interaction.

Script:

Start-Process -NoNewWindow -FilePath pw -ArgumentList @"
    threshold checkpoint create "WeeklyBackup" "WeeklyBackup"
"@
sleep -Seconds 3
$confirm = Select-String -pattern "About to over-write existing CheckPoint 'WeeklyBackup'." -Quiet

if ($confirm)
{
   Write-Host "Y`r" 
}

What I expect to see in the console:

D:\BMC_Software\ProactiveNet>pw threshold checkpoint create "WeeklyBackup" "Week
lyBackup"
About to over-write existing CheckPoint 'WeeklyBackup'. Do you want to proceed?
(y/n)

Then the user hits Y and the carriage return, and the process is completed. But I want this to be automated.

Thanks in advance for any advice.

+4
1
echo "Y`r" | pw

, PowerShell.

+3

All Articles