<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>youdidwhatwithtsql.com &#187; network settings</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/tag/network-settings/feed" rel="self" type="application/rss+xml" />
	<link>http://www.youdidwhatwithtsql.com</link>
	<description>making DBAs everywhere curse!</description>
	<lastBuildDate>Sat, 24 Jul 2010 16:26:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Auditing Network Adapters with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/auditing-network-adapters-with-powershell/126</link>
		<comments>http://www.youdidwhatwithtsql.com/auditing-network-adapters-with-powershell/126#comments</comments>
		<pubDate>Tue, 26 May 2009 17:40:39 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[network settings]]></category>
		<category><![CDATA[Powershell Scripting]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/auditing-network-adapters-with-powershell/126</guid>
		<description><![CDATA[Those boring network auditing tasks you have to do are now going to be a breeze with Powershell. With technologies like WMI accessible from Powershell there is virtually no limit to what you can do. I’m going to publish a series of articles showing how Powershell can be used to document your server and network. [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/auditing-network-adapters-with-powershell/126">Auditing Network Adapters with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Those boring network auditing tasks you have to do are now going to be a breeze with <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target="_blank">Powershell</a>. With technologies like <a href="http://en.wikipedia.org/wiki/Windows_Management_Instrumentation" target="_blank">WMI</a> accessible from <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target="_blank">Powershell</a> there is virtually no limit to what you can do. I’m going to publish a series of articles showing how <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target="_blank">Powershell</a> can be used to document your server and network. First here is a <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target="_blank">Powershell</a> script that can be used to document networking settings on a host.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p126code2'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1262"><td class="code" id="p126code2"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Function used for coalesce</span>
<span style="color: #0000FF;">function</span> coalesce<span style="color: #000000;">&#40;</span><span style="color: #800080;">$param</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$param</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$param</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&lt;not configured&gt;&quot;</span>;
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">return</span> <span style="color: #800080;">$param</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">function</span> appendToFile
<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">param</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$computer</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$adapterLine</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$fileName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;C:\$computer&quot;</span> <span style="color: pink;">+</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800000;">&quot;_&quot;</span> <span style="color: pink;">+</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800000;">&quot;NetworkAdapters.csv&quot;</span>;
	<span style="color: #008000;"># Does the file already exist?</span>
	<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Test-Path</span> <span style="color: #800080;">$fileName</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;"># Append text to file</span>
		<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800080;">$fileName</span> <span style="color: #800080;">$adapterLine</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>;
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">else</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;"># Create the file</span>
		<span style="color: #008080; font-weight: bold;">New-Item</span> <span style="color: #800080;">$fileName</span> <span style="color: pink;">-</span><span style="color: #008080; font-weight: bold;">type</span> file <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>
		<span style="color: #008000;"># Append the headers</span>
		<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800080;">$fileName</span> <span style="color: #800000;">&quot;adapterName,MACAddress,ipAddress,DefaultIPGateway,DHCPEnabled,DHCPServer,DNSDomain&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>;
		<span style="color: #008000;"># Append text to file</span>
		<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800080;">$fileName</span> <span style="color: #800080;">$adapterLine</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Set computer name here</span>
<span style="color: #800080;">$computer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;localhost&quot;</span>;
<span style="color: #008000;"># Set to true to show Network adapters with no configured IP address.</span>
<span style="color: #800080;">$showNoIP</span> <span style="color: pink;">=</span> <span style="color: #800080;">$false</span>;
&nbsp;
<span style="color: #800080;">$networkAdapters</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-Class</span> win32_networkadapter <span style="color: #008080; font-style: italic;">-computername</span> <span style="color: #800080;">$computer</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$networkAdapter</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$networkAdapters</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008000;"># Win32_NetworkAdapter properties</span>
	<span style="color: #800080;">$adapterName</span> <span style="color: pink;">=</span> coalesce<span style="color: #000000;">&#40;</span><span style="color: #800080;">$networkAdapter</span>.Name<span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$adapterStatus</span> <span style="color: pink;">=</span> coalesce<span style="color: #000000;">&#40;</span><span style="color: #800080;">$networkAdapter</span>.Status<span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$MACAddress</span> <span style="color: pink;">=</span> coalesce<span style="color: #000000;">&#40;</span><span style="color: #800080;">$networkAdapter</span>.MACAddress<span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #008000;"># Get the Index of the currrent adapter to retireve its configuration from another WMI class</span>
	<span style="color: #800080;">$adapterIndex</span> <span style="color: pink;">=</span> <span style="color: #800080;">$networkAdapter</span>.Index;
	<span style="color: #800080;">$adapterConfig</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-Class</span> Win32_NetworkAdapterConfiguration <span style="color: pink;">-</span><span style="color: #0000FF;">Filter</span> <span style="color: #800000;">&quot;Index = $adapterIndex AND ipenabled = 'true'&quot;</span> <span style="color: #008080; font-style: italic;">-computername</span> <span style="color: #800080;">$computer</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #008000;"># Win32_NetworkAdapterConfiguration properties</span>
	<span style="color: #800080;">$ipAddress</span> <span style="color: pink;">=</span> coalesce<span style="color: #000000;">&#40;</span><span style="color: #800080;">$adapterConfig</span>.IPAddress<span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$DefaultIPGateway</span> <span style="color: pink;">=</span> coalesce<span style="color: #000000;">&#40;</span><span style="color: #800080;">$adapterConfig</span>.DefaultIPGateway<span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$DHCPEnabled</span> <span style="color: pink;">=</span> coalesce<span style="color: #000000;">&#40;</span><span style="color: #800080;">$adapterConfig</span>.DHCPEnabled<span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$DHCPServer</span> <span style="color: pink;">=</span> coalesce<span style="color: #000000;">&#40;</span><span style="color: #800080;">$adapterConfig</span>.DHCPServer<span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$DNSDomain</span> <span style="color: pink;">=</span> coalesce<span style="color: #000000;">&#40;</span><span style="color: #800080;">$adapterConfig</span>.DNSDomain<span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #008000;"># Display info only for adapters with configured IP addresses</span>
	<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$ipAddress</span> <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">&quot;&lt;not configured&gt;&quot;</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;">$showNoIP</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$false</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$adapterLine</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;$adapterName,$MACAddress,$ipAddress,$DefaultIPGateway,$DHCPEnabled,$DHCPServer,$DNSDomain&quot;</span>;
		appendToFile <span style="color: pink;">-</span>computer <span style="color: #800000;">&quot;$computer&quot;</span> <span style="color: pink;">-</span>adapterLine <span style="color: #800000;">&quot;$adapterLine&quot;</span>;
	<span style="color: #000000;">&#125;</span>
	<span style="color: #008000;"># Display info for all adapters</span>
	<span style="color: #0000FF;">elseif</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$showNoIP</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$adapterLine</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;$adapterName,$MACAddress,$ipAddress,$DefaultIPGateway,$DHCPEnabled,$DHCPServer,$DNSDomain&quot;</span>;
		appendToFile <span style="color: pink;">-</span>computer <span style="color: #800000;">&quot;$computer&quot;</span> <span style="color: pink;">-</span>adapterLine <span style="color: #800000;">&quot;$adapterLine&quot;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Just change the <strong>$computer </strong>variable to whichever computer you wish to audit. This will produce a file called <strong>&lt;computer name&gt;_NetworkApaters.csv</strong> and will contain information similar to;</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="454">adapterName</td>
<td width="123">MACAddress</td>
<td width="86">ipAddress</td>
<td width="136">DefaultIPGateway</td>
<td width="104">DHCPEnabled</td>
<td width="127">DHCPServer</td>
<td width="136">DNSDomain</td>
</tr>
<tr>
<td>Realtek RTL8187B Wireless 802.11b/g 54Mbps USB 2.0 Network Adapter</td>
<td>00:16:44:6F:FF:65</td>
<td>192.168.0.2</td>
<td>192.168.0.1</td>
<td>TRUE</td>
<td>192.168.0.1</td>
<td>&lt;not configured&gt;</td>
</tr>
</tbody>
</table>
<p>The $<strong>showNoIP </strong>is set to only show adapters configured with <a href="http://en.wikipedia.org/wiki/TCP/IP" target="_blank">TCP/IP</a>. Set this to <strong>$true </strong>to make the script dump details of all adapters. </p>
<p>It would be fairly trivial to get this script to process a list of computers to document an entire network. I have shown this in <a href="http://www.youdidwhatwithtsql.com/monitoring-starting-services-with-powershell/113" target="_blank">other Powershell scripts</a> but will be demonstrating this again in a future post.</p>
<p><map name='google_ad_map_126_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/126?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_126_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=126&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fauditing-network-adapters-with-powershell%2F126' title="Auditing Network Adapters with Powershell" alt=" Auditing Network Adapters with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/auditing-network-adapters-with-powershell/126">Auditing Network Adapters with Powershell</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/auditing-network-adapters-with-powershell/126/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
