Created
April 11, 2011 04:04
-
-
Save stratalux/913044 to your computer and use it in GitHub Desktop.
SetDNS on Windows Node Recipe - Bad
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]}) | |
powershell_script = <<'POWERSHELL_SCRIPT' | |
# $DNSServers = "$env:MASTER_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