do until user input yes/no

前端 未结 3 1984
梦谈多话
梦谈多话 2020-12-02 01:17

I am trying to write a simple do..until loop and it does not work:

$yesNo = Read-Host -Prompt \'Do you want to add alternative DNS names or IPs          


        
3条回答
  •  借酒劲吻你
    2020-12-02 01:37

    I think you don't need two do-until loop. I also would prefer a do-while (while he is confirming with y or Y).

    Your string interpolation on the Add-Content doesn't work because you are using single quotes. I would leverage a format string here:

    $yesNo = Read-Host -prompt 'Do you want to add alternative DNS names or IPs into Certificate? Y/N: '
    if ($yesNo -eq 'y')
    {
        do 
        {
            $dnsipname = read-host -prompt "Please input DNS or IP as dns=alternativeCNname or ip=ipName: "
            Write-output "$dnsipname" 
            Add-Content -Path "D:\Scripts\expiringCerts\request.inf" -value ('`r`n_continue_ = "{0}"' -f $dnsipname)
            $strQuit = Read-Host " do you want to add another DNS? (Y/N)"                
        }
        while($strQuit -eq 'y')
    }
    

提交回复
热议问题