Skip to content

Instantly share code, notes, and snippets.

@codyde
Last active October 12, 2018 09:27
Show Gist options
  • Save codyde/393d48244a0a7eb6676b482edd4c6b35 to your computer and use it in GitHub Desktop.
Save codyde/393d48244a0a7eb6676b482edd4c6b35 to your computer and use it in GitHub Desktop.
DNS Update Script
[CmdletBinding()]
Param(
[Parameter(Mandatory = $True)]
[String]$Hostname,
[Parameter(Mandatory = $True)]
[String]$Domain,
[Parameter(Mandatory = $True)]
[String]$IP
)
Function Get-SafeString($value) {
if ($value -eq $null) {
Write-Output ''
} else {
Write-Output $value.ToString()
}
}
Function Invoke-DNSRecord($Hostname, $Domain, $IP) {
write-host "Hostname is $Hostname"
write-host "Domain is $Domain"
write-host "IP Address is $IP"
$props = @{
'Hostname' = Get-SafeString $Hostname
'Domain' = Get-SafeString $Domain
'IP' = Get-SafeString $IP
}
$Object = New-Object PSObject -Property $props
Write-Host "$Object"
Add-DnsServerResourceRecordA -name $Object.Hostname -ZoneName $Object.Domain -AllowUpdateAny -IPv4Address $Object.IP -TimeToLive 300
}
Invoke-DNSRecord -Hostname $Hostname -Domain $Domain -IP $IP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment