Created
November 5, 2017 18:33
-
-
Save rsyuzyov/61e39c50e300bbf4dbd5391484868ccb to your computer and use it in GitHub Desktop.
MS DNS - add or update CNAME
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Update-CNAME { | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Position=0,HelpMessage="Alias (short name)",Mandatory=$true,ValueFromPipeline=$true)] | |
| [string] $Alias, | |
| [Parameter(Position=1,HelpMessage="CName (FQDN)",Mandatory=$true,ValueFromPipeline=$true)] | |
| [string] $Name, | |
| [Parameter(Position=2,HelpMessage="Zone of the alupdatsdfias",Mandatory=$true,ValueFromPipeline=$true)] | |
| [string] $ZoneName, | |
| [Parameter(Position=3,HelpMessage="Domain controller",Mandatory=$true,ValueFromPipeline=$true)] | |
| [string] $ComputerName | |
| ) | |
| Try | |
| { | |
| Remove-DnsServerResourceRecord -Name $Alias -ZoneName $ZoneName -RRType CName -Force -ComputerName $ComputerName | |
| } | |
| Catch{} | |
| Try | |
| { | |
| Add-DnsServerResourceRecordCName -Name $Alias -HostNameAlias $Name -ZoneName $ZoneName -ComputerName $ComputerName | |
| } | |
| Catch | |
| { | |
| $Exception = $_.exception.Message | |
| Write-Warning "Alias update failed: $Exception" | |
| } | |
| } | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#Получение списка баз и создание альясов в dns для каждой базы:
Import-Module /scripts/update-cname.ps1
invoke-sqlcmd "select name from sys.databases where database_id > 4" -ServerInstance "srv-mssql" | ForEach-Object {Update-CNAME $_.name "srv-mssql.domain.local" "dbs.domain.local" "srv-dc"}