I am trying to write a simple script that will execute a console command in Windows, which will always ask for a confirmation for overwriting the existing data. I thought something like the below would work, but it appears I was mistaken (and no surprise, write-host doesn't interact with the command line, I believe it simply puts text on screen). Can anyone provide some advice on how to handle this? I need to be able to execute the script through task scheduler on a weekly basis with no 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 a user would hit Y and carriage-return and the process would be done. But I want this automated.
Thanks in advance for any advice.
echo "Y`r" | pw
This is typically used from batch files but it usually works just as well from PowerShell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With