Skip to content

Instantly share code, notes, and snippets.

@stratalux
Created April 11, 2011 05:24
Show Gist options
  • Save stratalux/913092 to your computer and use it in GitHub Desktop.
Save stratalux/913092 to your computer and use it in GitHub Desktop.
SetDNS
#
# Cookbook Name:: development
# Recipe:: setDNS
#
# Copyright 2011, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
powershell "Set Host Resolvers" do
parameters({'MASTER_DNS' => @node[:development][:MASTER_DNS]})
parameters({'SECOUNDARY_DNS' => @node[:development][:SECOUNDARY_DNS]})
powershell_script = <<'POWERSHELL_SCRIPT'
$DNSServers = "$env:MASTER_DNS","env:SECOUNDARY_DNS"
$message=""
function setDNS($DNSServers)
{
try
{
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration |where{$_.IPEnabled -eq "TRUE"}
Foreach($NIC in $NICs)
{
$message += $NIC.SetDNSServerSearchOrder(@($DNSServers)) | Out-String # set the DNS IPs and capture output to string
}
}
catch
{
$message += "An error occcured while setting NIC object." + "`n`rError: $_";
}
#write-host $message #if necessary, display result messages
}
setDNS($DNSServers)
POWERSHELL_SCRIPT
source(powershell_script)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment