<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Parsing dsquery output with Powershell</title>
	<atom:link href="http://andrekamman.com/parsing-dsquery-output-with-powershell/feed" rel="self" type="application/rss+xml" />
	<link>http://andrekamman.com/parsing-dsquery-output-with-powershell</link>
	<description>Just Another SQL Server DBA</description>
	<lastBuildDate>Thu, 15 Apr 2010 17:13:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Mike Sangrey</title>
		<link>http://andrekamman.com/parsing-dsquery-output-with-powershell/comment-page-1#comment-11</link>
		<dc:creator>Mike Sangrey</dc:creator>
		<pubDate>Thu, 11 Feb 2010 14:02:42 +0000</pubDate>
		<guid isPermaLink="false">http://andrekamman.com/?p=125#comment-11</guid>
		<description>Another way of handling this is with Regular Expressions (which are extremely powerful, once you get the hang of them).

@(dsquery computer -limit 0 &#124; %{[regex]::Replace($_, &quot;`&quot;CN=([^,]+),.*$&quot;, &#039;$1  &#039;)})

This uses the .Net Regex object&#039;s Replace method.  I won&#039;t repeat what is said above.  But the regular expression is &quot;`&quot;CN=([^,]+),.*$&quot;. 

Breaking it into pieces we have
`&quot;    An escaped quote, so this matches the quote
CN=   A literal string, so this matches the string CN=
(...) The stuff between the parens is a CAPTURED and will be stored in the $1
[^,]  Match anything but the comma
+     Do the previous match (the [^,]) one or more times.
,     A literal string, so this matches the comma
.     Match any character
*     Do the previous match (the any character) zero or more times
$     Match the end of the string.

So, what this regex does is throw away the &quot;CN= at the beginning of the string and also everything after the comma.  The stuff between the CN= and the comma is stored in the capture.

The Replace then takes the incoming string and replaces it with what was captured in the $1.</description>
		<content:encoded><![CDATA[<p>Another way of handling this is with Regular Expressions (which are extremely powerful, once you get the hang of them).</p>
<p>@(dsquery computer -limit 0 | %{[regex]::Replace($_, &#8220;`&#8221;CN=([^,]+),.*$&#8221;, &#8216;$1  &#8216;)})</p>
<p>This uses the .Net Regex object&#8217;s Replace method.  I won&#8217;t repeat what is said above.  But the regular expression is &#8220;`&#8221;CN=([^,]+),.*$&#8221;. </p>
<p>Breaking it into pieces we have<br />
`&#8221;    An escaped quote, so this matches the quote<br />
CN=   A literal string, so this matches the string CN=<br />
(&#8230;) The stuff between the parens is a CAPTURED and will be stored in the $1<br />
[^,]  Match anything but the comma<br />
+     Do the previous match (the [^,]) one or more times.<br />
,     A literal string, so this matches the comma<br />
.     Match any character<br />
*     Do the previous match (the any character) zero or more times<br />
$     Match the end of the string.</p>
<p>So, what this regex does is throw away the &#8220;CN= at the beginning of the string and also everything after the comma.  The stuff between the CN= and the comma is stored in the capture.</p>
<p>The Replace then takes the incoming string and replaces it with what was captured in the $1.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Find SQL Servers on your network with Powershell &#124; André Kamman</title>
		<link>http://andrekamman.com/parsing-dsquery-output-with-powershell/comment-page-1#comment-8</link>
		<dc:creator>Find SQL Servers on your network with Powershell &#124; André Kamman</dc:creator>
		<pubDate>Thu, 21 Jan 2010 21:20:50 +0000</pubDate>
		<guid isPermaLink="false">http://andrekamman.com/?p=125#comment-8</guid>
		<description>[...] created a list of servers for him to scan using this method)   Filed under: [...]</description>
		<content:encoded><![CDATA[<p>[...] created a list of servers for him to scan using this method)   Filed under: [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
