Created
April 11, 2011 05:24
-
-
Save stratalux/913092 to your computer and use it in GitHub Desktop.
SetDNS
This file contains 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
# | |
# 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