Skip to content

Instantly share code, notes, and snippets.

@weeyin83
Created March 26, 2021 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weeyin83/dd7f8aad86c0abc5db53ae6a03f14424 to your computer and use it in GitHub Desktop.
Save weeyin83/dd7f8aad86c0abc5db53ae6a03f14424 to your computer and use it in GitHub Desktop.
#If dns_srv3 is populated do the following
If($dns_srv3) {
#This stage added the second server as a nameserver to the zones created above
$zones | foreach-object {Add-DnsServerResourceRecord -Name $_ -NameServer $dns_srv2 -NS -ZoneName $_} $zones | foreach-object {Add-DnsServerResourceRecord -Name $_ -NameServer $dns_srv3 -NS -ZoneName $_}
#Create remote session and create a copy of the zones onto the secondary server
$session = New-PSSession -ComputerName $dns_srv2 -Credential $credentials ForEach ($z in $zones) {Invoke-Command -Session $session -ScriptBlock $scriptblock -Arg @($zones,$dns_ip1,$dns_srv2,$z)}
#Create remote session and create a copy of the zones onto the third server
$session2 = New-PSSession -ComputerName $dns_srv3 -Credential $credentials ForEach ($z in $zones) {Invoke-Command -Session $session2 -ScriptBlock $scriptblock -Arg @($zones,$dns_ip1,$dns_srv2,$z,$dns_srv3)} #Remove credential file Remove-Item C:\cred.txt
#Close remote session to the second server
Remove-PSSession $Session
#Close remote session to the third server
Remove-PSSession $Session2
#This checks if the script has ran with errors or not and outputs accordingly.
If ($Error[0]) { Write-Host "The script has completed but has completed with errors, please investigate and re-run script." -BackgroundColor Black -ForegroundColor Red   }  Else { Write-Host "The script has completed successfully." -BackgroundColor Black -ForegroundColor Yellow } } else #If there dns_srv3 is empty the script will do the following {
#This stage added the second server as a nameserver to the zones created above
$zones | foreach-object {Add-DnsServerResourceRecord -Name $_ -NameServer $dns_srv2 -NS -ZoneName $_}
#Create remote session and create a copy of the zones onto the secondary server
$session = New-PSSession -ComputerName $dns_srv2 -Credential $credentials ForEach ($z in $zones) {Invoke-Command -Session $session -ScriptBlock $scriptblock -Arg @($zones,$dns_ip1,$dns_srv2,$z)}
#Remove credential file
Remove-Item C:\cred.txt
#Close remote session
Remove-PSSession $Session
#This checks if the script has ran with errors or not and outputs accordingly.
If ($Error[0]) { Write-Host "The script has completed but has completed with errors, please investigate and re-run script." -BackgroundColor Black -ForegroundColor Red   }  Else { Write-Host "The script has completed successfully." -BackgroundColor Black -ForegroundColor Yellow } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment