none
How to supress confirmation prompt for Remove-DnsServerResourceRecord RRS feed

  • Question

  • The script below prompts to confirm, which I don't want. You can see that I'm using three different methods ($ConfirmPreference = "None" , -Confirm:$false , -Force). This is Windows Server 2012 (not R2) with PowerShell 3 and I am running PowerShell prompt as Administrator while logged in as a Domain Admin.

    Param (
        [Parameter(Mandatory=$True)]
        [string]$DnsSuffix,
    
        [Parameter(Mandatory=$True)]
        [string]$DnsServer,
    
        [Parameter(Mandatory=$True)]
        [string]$VMName,
    
        [Parameter(Mandatory=$True)]
        [string]$IPv4Address
    )
    
    Function Log-Output
    {
        Param(
            [String]$Message
        )
    <#
        http://blogs.msdn.com/b/timid/archive/2009/09/24/powershell-one-liner-what-s-the-function-name.aspx
        http://www.techtalkz.com/microsoft-windows-powershell/154158-getting-properties-current-process.html
        http://stackoverflow.com/questions/1169891/how-do-i-get-the-localhost-name-in-powershell
        https://technet.microsoft.com/en-us/library/hh849809(v=wps.620).aspx
    #>
    
        Write-Host "[$(Get-Date -Format o)][$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)][$([System.Net.Dns]::GetHostName())][$( Split-Path -Leaf $MyInvocation.ScriptName )][$pid][$( (Get-Variable MyInvocation -Scope 1).Value.MyCommand.Name )]  $($Message)"
    }
    
    Log-Output ""
    Log-Output "$($MyInvocation.MyCommand.Path) start"
    Log-Output ""
    Log-Output "`$DNSSuffix = $DNSSuffix"
    Log-Output "`$DnsServer = $DnsServer"
    Log-Output "`$VMName = $VMName"
    Log-Output "`$IPv4Address = $IPv4Address"
    
    If ( Test-Connection -ComputerName $DnsServer )
    {
        $CurrentARecord = Remove-DnsServerResourceRecord -ZoneName $DnsSuffix -ComputerName $DnsServer -RRType "A" -Name $VMName -RecordData $IPv4Address
        If ( $CurrentARecord )
        {
            Log-Output ""
            Log-Output "Remove-DnsServerResourceRecord -ZoneName $DnsSuffix -ComputerName $DnsServer -RRType `"A`" -Name $VMName -RecordData $IPv4Address -Confirm:$false -Force"
    	$ConfirmPreference = "None"
                        Remove-DnsServerResourceRecord -ZoneName $DnsSuffix -ComputerName $DnsServer -RRType "A" -Name $VMName -RecordData $IPv4Address -Confirm:$false -Force | Format-Table -AutoSize
            Log-Output ""
        } Else {
            Log-Output ""
            Log-Output "ERROR: unable to find DNS 'A' record for machine $VMName on DNS server $$DnsServer."
            Log-Output ""
        }
    } Else {
        Log-Output ""
        Log-Output "ERROR: unable to ping DNS server $DnsServe"
        Log-Output ""
    }
    
    
    Log-Output "$($MyInvocation.MyCommand.Path) end"
    Log-Output ""
    

    Friday, March 13, 2015 11:58 PM

Answers

  • what happens if you run just this one line?

    Remove-DnsServerResourceRecord -ZoneName $DnsSuffix -ComputerName $DnsServer -RRType A -Name $VMName -RecordData $IPv4Address -Confirm:$false -Force
     


    ¯\_(ツ)_/¯

    • Marked as answer by aenagy Monday, March 16, 2015 3:10 PM
    Monday, March 16, 2015 12:58 PM

All replies

  • Have you notified the author of the script.

    ¯\_(ツ)_/¯

    Saturday, March 14, 2015 1:05 AM
  • I am the author.
    Monday, March 16, 2015 12:39 PM
  • what happens if you run just this one line?

    Remove-DnsServerResourceRecord -ZoneName $DnsSuffix -ComputerName $DnsServer -RRType A -Name $VMName -RecordData $IPv4Address -Confirm:$false -Force
     


    ¯\_(ツ)_/¯

    • Marked as answer by aenagy Monday, March 16, 2015 3:10 PM
    Monday, March 16, 2015 12:58 PM
  • I found the problem: it's the line that begins with

    $CurrentARecord = Remove-DnsServerResourceRecord ....

    I didn't realize that I hadn't finished the edits necessary to change this to Get-DnsServerResourceRecord. After finishing these edits the script now works as intended.

    I need a vacation.

    Thanks again.

    • Edited by aenagy Monday, March 16, 2015 3:11 PM
    Monday, March 16, 2015 3:10 PM