Skip to content

Instantly share code, notes, and snippets.

@stratalux
Created April 10, 2011 15:06
Show Gist options
  • Save stratalux/912421 to your computer and use it in GitHub Desktop.
Save stratalux/912421 to your computer and use it in GitHub Desktop.
Chef Powershell Recipe example
# Cookbook Name:: windows
# Recipe:: resolver
#
# Copyright 2011
#
# All rights reserved
# Set Resolver
powershell "Set Resolver" do
powershell_script = <<'POWERSHELL_SCRIPT'
$DNSServers = "192.168.1.108","206.13.30.12","206.13.29.12"
$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