-
- Novice
- Posts: 5
- Liked: never
- Joined: Jul 09, 2021 12:39 am
- Full Name: YONGKWAN KIM
- Contact:
How do I automatically answer “yes” to a prompt in Powershell?
Hello, I'm Veeam Backup and powershell scripts Beginner.
How can I input "yes" as an answer to an interactive question in a PowerShell session?
I run the recovery image creation script.
if there is an 192.168.100.xx existing iso file, do you want to replace it? message appears.
I want to automatically say Yes(y) here, is there any way?
And is it possible to automatically enter the ISO file name as the HostName or backup policy name?
This is my script.
# Get computer names from text file
$names = Get-Content -Path 'C:\Temp\computers.txt'
# Get the most current list of physical computers managed by VBR
$computers = Get-VBRDiscoveredComputer
# Determine the centralised path for ISO
$path = 'C:\Temp\'
foreach ($name in $names) {
# Find physical computers with the corresponding names
$computer = $computers | where {$_.Name -eq $name}
if ($computer) {
# If such computer is managed by VBR, construct custom path for ISO image and compose ISO target object
$ISOPath = "$($path)$($computer.Name).iso"
$ISOtarget = New-VBRRecoveryMediaISOTarget -Path $ISOPath
# Create recovery media for the computer in question
Add-VBRDiscoveredComputerRecoveryMedia -DiscoveredComputer $computer -RecoveryMediaTarget $ISOtarget
}
else {
Write-Host "Computer with name $name wasn't found"
}
}
How can I input "yes" as an answer to an interactive question in a PowerShell session?
I run the recovery image creation script.
if there is an 192.168.100.xx existing iso file, do you want to replace it? message appears.
I want to automatically say Yes(y) here, is there any way?
And is it possible to automatically enter the ISO file name as the HostName or backup policy name?
This is my script.
# Get computer names from text file
$names = Get-Content -Path 'C:\Temp\computers.txt'
# Get the most current list of physical computers managed by VBR
$computers = Get-VBRDiscoveredComputer
# Determine the centralised path for ISO
$path = 'C:\Temp\'
foreach ($name in $names) {
# Find physical computers with the corresponding names
$computer = $computers | where {$_.Name -eq $name}
if ($computer) {
# If such computer is managed by VBR, construct custom path for ISO image and compose ISO target object
$ISOPath = "$($path)$($computer.Name).iso"
$ISOtarget = New-VBRRecoveryMediaISOTarget -Path $ISOPath
# Create recovery media for the computer in question
Add-VBRDiscoveredComputerRecoveryMedia -DiscoveredComputer $computer -RecoveryMediaTarget $ISOtarget
}
else {
Write-Host "Computer with name $name wasn't found"
}
}
-
- VP, Product Management
- Posts: 7018
- Liked: 1493 times
- Joined: May 04, 2011 8:36 am
- Full Name: Andreas Neufert
- Location: Germany
- Contact:
-
- Novice
- Posts: 5
- Liked: never
- Joined: Jul 09, 2021 12:39 am
- Full Name: YONGKWAN KIM
- Contact:
Re: How do I automatically answer “yes” to a prompt in Powershell?
Then, can I just type -Force true after $ISOtarget?
-
- VP, Product Management
- Posts: 7018
- Liked: 1493 times
- Joined: May 04, 2011 8:36 am
- Full Name: Andreas Neufert
- Location: Germany
- Contact:
Re: How do I automatically answer “yes” to a prompt in Powershell?
-force
is enough
is enough
-
- Veteran
- Posts: 1143
- Liked: 302 times
- Joined: Apr 27, 2020 12:46 pm
- Full Name: Natalia Lupacheva
- Contact:
Re: How do I automatically answer “yes” to a prompt in Powershell?
Hi Yongkwan,
Just to clarify - if I understand your doubts correctly - yes, you are right, you can put "-Force" option right after $ISOtarget parameter, after this:
Add-VBRDiscoveredComputerRecoveryMedia -DiscoveredComputer $computer -RecoveryMediaTarget $ISOtarget
Thanks!
Just to clarify - if I understand your doubts correctly - yes, you are right, you can put "-Force" option right after $ISOtarget parameter, after this:
Add-VBRDiscoveredComputerRecoveryMedia -DiscoveredComputer $computer -RecoveryMediaTarget $ISOtarget
Thanks!
-
- Novice
- Posts: 5
- Liked: never
- Joined: Jul 09, 2021 12:39 am
- Full Name: YONGKWAN KIM
- Contact:
Re: How do I automatically answer “yes” to a prompt in Powershell?
thx, but i type -force after $ISOtarget, The same message appear.
However, even if you input No(N) here, the ISO file is received.
I want to automatically get ISO recovery image without N or Y input.
However, even if you input No(N) here, the ISO file is received.
I want to automatically get ISO recovery image without N or Y input.
-
- Product Manager
- Posts: 5775
- Liked: 1213 times
- Joined: Jul 15, 2013 11:09 am
- Full Name: Niels Engelen
- Contact:
Re: How do I automatically answer “yes” to a prompt in Powershell?
I believe u should use -force:$true in this case.
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
GitHub: https://github.com/nielsengelen
-
- Novice
- Posts: 5
- Liked: never
- Joined: Jul 09, 2021 12:39 am
- Full Name: YONGKWAN KIM
- Contact:
Re: How do I automatically answer “yes” to a prompt in Powershell?
Thanks everyone for the replies. But when I use -force:$true it keeps saying "do you want to replace it?" this comes out
-
- Product Manager
- Posts: 5775
- Liked: 1213 times
- Joined: Jul 15, 2013 11:09 am
- Full Name: Niels Engelen
- Contact:
Re: How do I automatically answer “yes” to a prompt in Powershell?
How about echoing "y" before u run the command?
or add the -Confirm option:
I can't test it right now so I'm relying on typical solutions to say "y" in PowerShell
Code: Select all
echo y | $ISOtarget = New-VBRRecoveryMediaISOTarget -Path $ISOPath
Code: Select all
$ISOtarget = New-VBRRecoveryMediaISOTarget -Path $ISOPath -Confirm:$false
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
GitHub: https://github.com/nielsengelen
-
- Veteran
- Posts: 643
- Liked: 312 times
- Joined: Aug 04, 2019 2:57 pm
- Full Name: Harvey
- Contact:
Re: How do I automatically answer “yes” to a prompt in Powershell?
Hello Yongkwan Kim,
I took a peek with a decompiler at the method used for this cmdlet, and unless a Veeam person wants to say otherwise, the dependent method accepts no parameters besides a target path for the proposed Recovery ISO File. CheckTargetIsoFileExistanceSafe is the method backing this part of the cmdlet and it has a simple workflow:
1. Check if the target file already exists
2. Ask the user to overwrite.
3. If No to 2, then break and fail (the method returns $false)
4. If Yes to 2, then continue on as it's safe to overwrite.
So as I see it, you cannot handle this with the cmdlet itself.
I would propose you write a logic check before the RecoveryMedia creation and handle the file checking before processing the cmdlet, something like:
You can delete it, rename the file, append something to $TargetISOFile (I actually like this personally, but that's just me)
But seems you will need to do this processing yourself.
I took a peek with a decompiler at the method used for this cmdlet, and unless a Veeam person wants to say otherwise, the dependent method accepts no parameters besides a target path for the proposed Recovery ISO File. CheckTargetIsoFileExistanceSafe is the method backing this part of the cmdlet and it has a simple workflow:
1. Check if the target file already exists
2. Ask the user to overwrite.
3. If No to 2, then break and fail (the method returns $false)
4. If Yes to 2, then continue on as it's safe to overwrite.
So as I see it, you cannot handle this with the cmdlet itself.
I would propose you write a logic check before the RecoveryMedia creation and handle the file checking before processing the cmdlet, something like:
Code: Select all
If(Test-Path $TargetISOFile){
do Action-on-ISO file
}
But seems you will need to do this processing yourself.
-
- Novice
- Posts: 5
- Liked: never
- Joined: Jul 09, 2021 12:39 am
- Full Name: YONGKWAN KIM
- Contact:
Re: How do I automatically answer “yes” to a prompt in Powershell?
Thank you all very much!!
Who is online
Users browsing this forum: Google [Bot] and 13 guests