<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Pathological Scripter</title>
	<atom:link href="http://pathologicalscripter.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://pathologicalscripter.wordpress.com</link>
	<description>PowerShell Spoken Here</description>
	<lastBuildDate>Mon, 16 Jul 2007 19:15:26 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
		<url>http://www.gravatar.com/blavatar/47b8b16a5a6a04b3f75e63056116e0ad?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Pathological Scripter</title>
		<link>http://pathologicalscripter.wordpress.com</link>
	</image>
			<item>
		<title>Power &#8220;Stuff&#8221;</title>
		<link>http://pathologicalscripter.wordpress.com/2007/07/16/power-stuff/</link>
		<comments>http://pathologicalscripter.wordpress.com/2007/07/16/power-stuff/#comments</comments>
		<pubDate>Mon, 16 Jul 2007 19:15:26 +0000</pubDate>
		<dc:creator>pathologicalscripter</dc:creator>
		
		<guid isPermaLink="false">http://pathologicalscripter.wordpress.com/2007/07/16/power-stuff/</guid>
		<description><![CDATA[&#8220;PowerGadgets&#8221; is an interesting looking data visualization product that works with PowerShell. Graphs, charts, dials, maps and gauges, what&#8217;s not to like?  
According to their web site &#8220;As a Windows PowerShell Snapin, PowerGadgets lets you easily explore, visualize and monitor enterprise data from virtually any data source, including traditional databases and text files, with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=19&subd=pathologicalscripter&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://www.powergadgets.com">&#8220;PowerGadgets&#8221;</a> is an interesting looking data visualization product that works with PowerShell. Graphs, charts, dials, maps and gauges, what&#8217;s not to like? <img src='http://s.wordpress.com/wp-includes/images/smilies/face-smile.png' alt=':-)' class='wp-smiley' /> </p>
<p>According to their web site &#8220;<em>As a Windows PowerShell Snapin, PowerGadgets lets you easily explore, visualize and monitor enterprise data from virtually any data source, including traditional databases and text files, with little or no coding involved</em>.&#8221;</p>
<p>They&#8217;re currently running a promotion that they&#8217;re calling their <a href="http://www.powergadgets.com/mvp/">PowerGadgets MVP Program</a>. Tell them a little about yourself and they may give you a free copy of PowerGadgets. I&#8217;ve been wanting to look into this product but didn&#8217;t have a budget for it. I recalled a &#8220;negotiating skills&#8221; course I took a long time ago whose motto was &#8220;if you don&#8217;t ask, they can&#8217;t say yes&#8221;, so I filled out their form over the weekend. Got my free license in this morning&#8217;s email. Cool. So &#8220;thanks&#8221; to the nice folks at PowerGadgers. Now to get busy and learn how to use it.</p>
<p>Not to be confused with the above is Andrew Peter&#8217;s <a href="http://andrewpeters.net/powershell-gadget/">&#8220;PowerShell Gadget&#8221;</a> which he describes as &#8220;<em>a small gadget that hosts the PowerShell console window in your Sidebar. Commands can be entered straight into the collapsed gadget or, by clicking on the PowerShell icon, the complete PowerShell console is available</em>&#8220;. This sounds so interesting that I&#8217;m going to have to fire up my Vista test machine just to give it a spin.</p>
<p>Another couple products that I just found are both from <a href="http://www.powerlocker.com/">&#8220;PowerLocker&#8221;</a>. Powerlocker (&#8221;<em>Encrypt and protect your PowerShell scripts</em>&#8220;) and PowerPad (&#8221;<em>Quickly edit multi-line scripts, functions, or script-blocks</em>&#8220;) both have &#8220;community&#8221; (read: free) versions, although the free PowerLocker version is limited to 10 line scripts. The paid version of Powerlocker obviously has no line limit. I&#8217;ll try both of them, although I&#8217;m kind of a die-hard vi user. And I don&#8217;t need to encrypt anything at this point, but it sounds interesting to test.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pathologicalscripter.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pathologicalscripter.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pathologicalscripter.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pathologicalscripter.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pathologicalscripter.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pathologicalscripter.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pathologicalscripter.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pathologicalscripter.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pathologicalscripter.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pathologicalscripter.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pathologicalscripter.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pathologicalscripter.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=19&subd=pathologicalscripter&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pathologicalscripter.wordpress.com/2007/07/16/power-stuff/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2df19fa061166c4f4a848ccc8eacdf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pathologicalscripter</media:title>
		</media:content>
	</item>
		<item>
		<title>Active Directory Explorer 1.0</title>
		<link>http://pathologicalscripter.wordpress.com/2007/07/15/active-directory-explorer-10/</link>
		<comments>http://pathologicalscripter.wordpress.com/2007/07/15/active-directory-explorer-10/#comments</comments>
		<pubDate>Sun, 15 Jul 2007 13:59:08 +0000</pubDate>
		<dc:creator>pathologicalscripter</dc:creator>
		
		<guid isPermaLink="false">http://pathologicalscripter.wordpress.com/2007/07/15/active-directory-explorer-10/</guid>
		<description><![CDATA[I use AdsiEdit an awful lot. Rarely to actually make changes in AD, but mostly to view or search for objects in AD &#8211; looking at attributes, etc. - in order to explore AD. Great tool but in order to search AD, I&#8217;d have to switch to LDP or ADUC or some other tool and then go [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=18&subd=pathologicalscripter&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I use AdsiEdit an awful lot. Rarely to actually make changes in AD, but mostly to view or search for objects in AD &#8211; looking at attributes, etc. - in order to explore AD. Great tool but in order to search AD, I&#8217;d have to switch to LDP or ADUC or some other tool and then go back to AdsiEdit to view the objects that I found. (Of course, now I mostly search with PowerShell but I still prefer a GUI tool for actually viewing the objects/attributes I&#8217;m researching.)</p>
<p>So I was interested to find that Microsoft has released a free download of <a href="http://www.microsoft.com/technet/sysinternals/utilities/adexplorer.mspx">Active Directory Explorer 1.0</a>, which was written by Bryce Cogswell and Mark Russinovich of SysInternals fame. Here&#8217;s the description from the tool itself:</p>
<blockquote><p>Active Directory Explorer (AD Explorer) is an advanced Active Directory (AD) viewer and editor. You can use AD Explorer to easily navigate an AD database, define favorite locations, view object properties and attributes without having to open dialog boxes, edit permissions, view an object&#8217;s schema, and execute sophisticated searches that you can save and re-execute.</p>
<p>AD Explorer also includes the ability to save snapshots of an AD database for off-line viewing and comparisons. When you load a saved snapshot you can navigate and explorer it as you would a live database. If you have two snapshots of an AD database you can use AD Explorer&#8217;s comparison functionality to see what objects, attributes and security permissions changed between them.</p></blockquote>
<p>I&#8217;m still exploring the tool, but here&#8217;s my impressions to date.</p>
<p>First, the visual presentation. Similar to AdsiEdit, but when you select an object on the left side of the interface, it immediately displays the populated attributes on the right side. Much quicker to use than AdsiEdit in this respect. Right-click on the object and you can view the oject&#8217;s security and attributes, as well as jump directly to the object&#8217;s schema object. It doesn&#8217;t appear to show unpopulated attributes. AdsiEdit seems to win on this point &#8211; you can toggle between displaying all possible attributes and only those wth values.</p>
<p>It also offers a history mechanism so you can backtrack through the containers and objects you&#8217;ve already visited.</p>
<p>Next, the search capability. It&#8217;s similar to the search dialog in ADUC, but it gives an extensive list of classes to choose from, as well as a dropdown box of the relevant attributes once you&#8217;ve selected a class. More flexible than ADUC in that regard but it doesn&#8217;t seem to allow you to create your own arbitrary LDAP search strings like ADUC does, nor does it seem to allow for &#8220;or&#8221; conditions, only &#8220;and&#8221; conditions. Unless I&#8217;ve missed something, that seems rather limiting.</p>
<p>Finally, the &#8220;snap-shot&#8221; capability. The documentation says that you can save and reload snapshots into the tool, as well as compare selected parts of two saved snapshots. Haven&#8217;t used it yet, but it looks like it might be useful in validating and documenting changes in AD. Our change management folks would like that. Soon as I get my test environment rebuilt, I&#8217;ll test that feature.</p>
<p>So my overall impression is that it&#8217;s worth further evaluation, even though it doesn&#8217;t seem to answer all my wish-list regarding search capabilities and attribute presentation. But for a first version, and a free tool at that, it&#8217;s a welcome addition to the tool-kit.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pathologicalscripter.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pathologicalscripter.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pathologicalscripter.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pathologicalscripter.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pathologicalscripter.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pathologicalscripter.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pathologicalscripter.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pathologicalscripter.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pathologicalscripter.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pathologicalscripter.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pathologicalscripter.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pathologicalscripter.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=18&subd=pathologicalscripter&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pathologicalscripter.wordpress.com/2007/07/15/active-directory-explorer-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2df19fa061166c4f4a848ccc8eacdf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pathologicalscripter</media:title>
		</media:content>
	</item>
		<item>
		<title>out-this, out-that</title>
		<link>http://pathologicalscripter.wordpress.com/2007/07/04/out-this-out-that/</link>
		<comments>http://pathologicalscripter.wordpress.com/2007/07/04/out-this-out-that/#comments</comments>
		<pubDate>Thu, 05 Jul 2007 02:34:45 +0000</pubDate>
		<dc:creator>pathologicalscripter</dc:creator>
		
		<guid isPermaLink="false">http://pathologicalscripter.wordpress.com/2007/07/04/out-this-out-that/</guid>
		<description><![CDATA[I&#8217;ve been doing a lot of work recently where I export data to a csv file and then open the file with Excel so I can convert it to a spreadsheet. But I&#8217;m inherently lazy so I went looking for an out-excel cmdlet or some such that would allow me to pipe data directly to Excel. I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=15&subd=pathologicalscripter&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been doing a lot of work recently where I export data to a csv file and then open the file with Excel so I can convert it to a spreadsheet. But I&#8217;m inherently lazy so I went looking for an out-excel cmdlet or some such that would allow me to pipe data directly to Excel. I found code samples of how to start Excel and how to write to cells in a worksheet, but couldn&#8217;t find what I wanted, so I wrote an out-excel function.</p>
<p>The basic behavior I wanted was to be able to do something like this -<br />
<em>get-process | where {$_.handles -gt 500} | select name,handles,path | out-excel</em><br />
and get an open workbook in Excel where the column headers were the names of the properties and where each row corresponded to an object in the pipeline.</p>
<p>I cobbled together some code which worked fine but then I wanted more. I knew that the convertto-html cmdlet has a <em>-property </em> parameter which allows you to select the specific properties you want, so I decided to add that. Now I could do something like this -<br />
<em>get-process | where {$_.handles -gt 500} | out-excel -pr name,handles,path</em></p>
<p>I&#8217;ve been doing a lot of ad-hoc Active Directory searching and reporting, sometimes retrieving DirectoryEntry objects and sometimes only retrieving SearchResult objects. SearchResults are odd creatures that require way too many keystrokes since instead of typing something nice and short like -<br />
<em>get-searchresults -type user,lockedout -raw | out-excel name, userprincipalname</em><br />
I would have to type something like this -<br />
<em>get-searchresults -type user,lockedout -raw | select @{n=&#8221;Name&#8221;;e={$_.properties.name}},<br />
    @{n=&#8221;UPN&#8221;;e={$_.properties.userprincipalname}}| out-excelname</em></p>
<p>(That <em>get-searchresults</em> function is a tool I&#8217;ve built and added to over time to make my AD searching easier. Normally it returns DirectoryEntry objects, but the -raw switch lets it return the SearchResult objects directly. Saves time when I just need the results of the query and don&#8217;t actually need to do anything with the corresponding DirectoryEntry objects. I need to write about that sometime. But did I mention that I was lazy?)</p>
<p>So I added a <em>-raw</em>  switch. Now I can do this -<br />
<em>get-searchresults -type user,lockedout -raw | out-excelname -pr name,userprincipalname -raw</em></p>
<p>The function itself is relatively straightforward.</p>
<p>The <em>begin </em> section starts Excel, creates a workbook and initializes  two variables.</p>
<p>In the <em>process</em> section, when the first object is encountered, we use the property list to write the property names in the first row. (If we weren&#8217;t provided a property list, we just build one based on the properties of the first object.) At the same time, we build a hash table so later we can look up a property name and find the corresponding column.</p>
<p>After this, we can process each object, enumerating the property names in our header table and writing the matching value from the object to the appropriate column. Using a hash table has the advantage that we don&#8217;t have to worry about missing properties or the &#8220;ordering&#8221; of the properties in the columns.</p>
<p>In the <em>end</em>  section, we just resize all the columns to fit the data. Now we have a spreadsheet open for further analysis in Excel or that we can save for later.</p>
<p>Here&#8217;s the function in its entirety &#8211; <a href="http://pathologicalscripter.wordpress.com/out-excel/">out-excel</a></p>
<blockquote></blockquote>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pathologicalscripter.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pathologicalscripter.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pathologicalscripter.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pathologicalscripter.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pathologicalscripter.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pathologicalscripter.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pathologicalscripter.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pathologicalscripter.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pathologicalscripter.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pathologicalscripter.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pathologicalscripter.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pathologicalscripter.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=15&subd=pathologicalscripter&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pathologicalscripter.wordpress.com/2007/07/04/out-this-out-that/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2df19fa061166c4f4a848ccc8eacdf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pathologicalscripter</media:title>
		</media:content>
	</item>
		<item>
		<title>Bruce Payette&#8217;s new book</title>
		<link>http://pathologicalscripter.wordpress.com/2006/10/18/bruce-payettes-new-book/</link>
		<comments>http://pathologicalscripter.wordpress.com/2006/10/18/bruce-payettes-new-book/#comments</comments>
		<pubDate>Wed, 18 Oct 2006 22:36:15 +0000</pubDate>
		<dc:creator>pathologicalscripter</dc:creator>
		
		<guid isPermaLink="false">http://pathologicalscripter.wordpress.com/2006/10/18/bruce-payettes-new-book/</guid>
		<description><![CDATA[Bruce Payette is a founding member of the Windows PowerShell team, the author of the Windows PowerShell language interpreter, and one of the key designers of the Windows PowerShell language.
I got my copy today of Bruce Payette&#8217;s soon-to-be-released book &#8220;Windows Powershell in Action&#8221;. While the final version is not yet available, you can buy an &#8220;Early [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=13&subd=pathologicalscripter&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Bruce Payette is a founding member of the Windows PowerShell team, the author of the Windows PowerShell language interpreter, and one of the key designers of the Windows PowerShell language.</p>
<p>I got my copy today of Bruce Payette&#8217;s soon-to-be-released book &#8220;Windows Powershell in Action&#8221;. While the final version is not yet available, you can buy an &#8220;Early Access Edition&#8221; from the <a href="http://www.manning.com/payette">publisher&#8217;s website</a> right now.  That allows you to download a PDF version of the unedited draft now and then receive the final published copy in paper and/or ebook version when released. Since my wife is a &#8220;bookie&#8221; (the kind that sells books, not betting slips), I&#8217;m accustomed to reading pre-publication editions of books. Plus I&#8217;m impatient and wanted it <em>right now</em>. Downloading a PDF beats FedEx every time.</p>
<p>At any rate, I&#8217;m only in chapter 2 since I&#8217;ve only been able to read it occasionally at work today. But it looks to be just what I was looking for. Highly recommended.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pathologicalscripter.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pathologicalscripter.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pathologicalscripter.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pathologicalscripter.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pathologicalscripter.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pathologicalscripter.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pathologicalscripter.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pathologicalscripter.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pathologicalscripter.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pathologicalscripter.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pathologicalscripter.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pathologicalscripter.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=13&subd=pathologicalscripter&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pathologicalscripter.wordpress.com/2006/10/18/bruce-payettes-new-book/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2df19fa061166c4f4a848ccc8eacdf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pathologicalscripter</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Invisible&#8221; methods for ADSI?</title>
		<link>http://pathologicalscripter.wordpress.com/2006/09/28/invisible-methods-for-adsi/</link>
		<comments>http://pathologicalscripter.wordpress.com/2006/09/28/invisible-methods-for-adsi/#comments</comments>
		<pubDate>Thu, 28 Sep 2006 22:45:03 +0000</pubDate>
		<dc:creator>pathologicalscripter</dc:creator>
		
		<guid isPermaLink="false">http://pathologicalscripter.wordpress.com/2006/09/28/invisible-methods-for-adsi/</guid>
		<description><![CDATA[RC2&#8217;s new [ADSI] type shortcut showed up without any methods, only properties, causing quite a bit of confusion, given that a lot of working scripts are now broken. Aruk Kumaravel, Windows PowerShell Development Manager, provided a little clarification in a posting at microsoft.public.windows.powershell. The part I still don&#8217;t understand is why they would even consider [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=10&subd=pathologicalscripter&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>RC2&#8217;s new [ADSI] type shortcut showed up without any methods, only properties, causing quite a bit of confusion, given that a lot of working scripts are now broken. Aruk Kumaravel, Windows PowerShell Development Manager, provided a little clarification in a posting at microsoft.public.windows.powershell. The part I still don&#8217;t understand is why they would even consider not exposing the methods via get-member&#8230;</p>
<blockquote><p>Folks,<br />
I know that many of  you are wondering about ADSI changes in RC2.  I am currently in the process of  writing a blog to explain  the new ADSI support. People are wondering as to why methods are not showing up in  GM.  .Net DirectoryService Object is wrapper around the underlying AD com object. Based on the  type of AD com object, it can have any number of interfaces like  IADs, IADsContainer, IADsNameSpaces   etc.   .Net DirectoryService doesn&#8217;t expose all the functionality of the underlying AD object. That is the reason why  DirectoryEntry object has property called  NativeObject  to access the underlying COM object. The Native COM object doesn&#8217;t have all the metadata to determine all the methods that it provides.  Faced with this constraint, we chose a route similar to VBScript.  When we decided to support AD Scripting, we wanted to make it as simple as possible but at the same time expose of the full functionality of  AD. VBSCript provides this functionality with set of following methods alone</p>
<p>Create<br />
Put<br />
Set<br />
PutEx<br />
SetEx<br />
GetInfo<br />
SetInfo</p>
<p>The above list of methods will allow you to do pretty much all ADSI scripting tasks.  We thought of exposing these set of methods as part of Get-Member call but decided against it (In retrospect, maybe we should have exposed these).  Not exposing the methods is what throws people off with the new ADSI support.</p>
<p>I had  written some blog posts on using new ADSI support in the following blogs.  Please take a look at it. I used  ADAM to test these scripts</p>
<p><a target="winout" href="http://blogs.msdn.com/arulk/archive/2006/07/25/678137.aspx" class="WNAnc">http://blogs.msdn.com/arulk/archive/2006/07/25/678137.aspx</a><br />
<a target="winout" href="http://blogs.msdn.com/arulk/archive/2006/07/28/682289.aspx" class="WNAnc">http://blogs.msdn.com/arulk/archive/2006/07/28/682289.aspx</a><br />
<a target="winout" href="http://blogs.msdn.com/arulk/archive/2006/08/24/719241.aspx" class="WNAnc">http://blogs.msdn.com/arulk/archive/2006/08/24/719241.aspx</a></p>
<p>For Advanced script users, who are still interested in access to the DirectoryEntry object,  it is available as PSBase property in the PSObject. People who are familiar with ADSI scripting with VBScript will find the transition much easier.  If you are used to using DirectoryEntry object then the new changes would be disruptive to existing mental model.</p>
<p>I will  look into some of the examples people have provided in the blog posts and convert few of this into new ADSI syntax and share it  with you.</p>
<p>thanks</p>
<p>Aruk Kumaravel [MSFT]<br />
Windows PowerShell Development Manager<br />
Microsoft Corporation</p>
</blockquote>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pathologicalscripter.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pathologicalscripter.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pathologicalscripter.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pathologicalscripter.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pathologicalscripter.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pathologicalscripter.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pathologicalscripter.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pathologicalscripter.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pathologicalscripter.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pathologicalscripter.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pathologicalscripter.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pathologicalscripter.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=10&subd=pathologicalscripter&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pathologicalscripter.wordpress.com/2006/09/28/invisible-methods-for-adsi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2df19fa061166c4f4a848ccc8eacdf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pathologicalscripter</media:title>
		</media:content>
	</item>
		<item>
		<title>I want my DirectoryEntry methods back</title>
		<link>http://pathologicalscripter.wordpress.com/2006/09/28/i-want-my-directoryentry-methods-back/</link>
		<comments>http://pathologicalscripter.wordpress.com/2006/09/28/i-want-my-directoryentry-methods-back/#comments</comments>
		<pubDate>Thu, 28 Sep 2006 19:44:01 +0000</pubDate>
		<dc:creator>pathologicalscripter</dc:creator>
		
		<guid isPermaLink="false">http://pathologicalscripter.wordpress.com/2006/09/28/i-want-my-directoryentry-methods-back/</guid>
		<description><![CDATA[RC2 is out and we have a new type alias [ADSI] for dealing with DirectoryEntry objects in AD, but inexplicably (at least to me), we&#8217;ve lost all the methods associated with that class unless you change everything to use psbase. 
So instead of saying something like
PS&#62;$Entry = New-Object DirectoryServices.DirectoryEntry (&#8221;LDAP://dc=domain,dc=com&#8221;)
I can say
PS&#62;$Entry = [ADSI] &#8220;LDAP://dc=domain,dc=com&#8221;
But instead of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=9&subd=pathologicalscripter&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>RC2 is out and we have a new type alias [ADSI] for dealing with DirectoryEntry objects in AD, but inexplicably (at least to me), we&#8217;ve lost all the methods associated with that class unless you change everything to use <em>psbase</em>. </p>
<p>So instead of saying something like</p>
<blockquote><p>PS&gt;$Entry = New-Object DirectoryServices.DirectoryEntry (&#8221;LDAP://dc=domain,dc=com&#8221;)</p></blockquote>
<p>I can say</p>
<blockquote><p>PS&gt;$Entry = [ADSI] &#8220;LDAP://dc=domain,dc=com&#8221;</p></blockquote>
<p>But instead of saying</p>
<blockquote><p>PS&gt;$Entry.get_Children()</p></blockquote>
<p>I have to say</p>
<blockquote><p>PS&gt;$Entry.psbase.get_Children() </p></blockquote>
<p>And a fair amount of working code no longer works.</p>
<p>I don&#8217;t pretend to understand the discussion on the newsgroup about &#8220;adapting&#8221; and why using <em>psbase </em>is better than before. So in the spirit of PowerShell, I&#8217;ve just <a href="http://pathologicalscripter.wordpress.com/?page_id=8">extended the type definition</a> for DirectoryEntry so that I can still use the previous code.</p>
<p>For each of the previous methods for DirectoryEntry, I&#8217;ve added a ScriptMethod. So for example,</p>
<blockquote><p>&lt;ScriptMethod&gt;<br />
  &lt;Name&gt;get_Children&lt;/Name&gt;<br />
  &lt;Script&gt;<br />
    $this.psbase.get_Children()<br />
  &lt;/Script&gt;<br />
&lt;/ScriptMethod&gt;</p></blockquote>
<p>allows me to continue to use</p>
<blockquote><p>$Entry.get_Children()</p></blockquote>
<p>without the <em>psbase</em> &#8220;layer&#8221;.</p>
<p>This also allows previous code like MoW&#8217;s</p>
<blockquote><p>&lt;ScriptProperty&gt;<br />
  &lt;Name&gt;PasswordLastChanged&lt;/Name&gt;<br />
  &lt;GetScriptBlock&gt;<br />
  $this.InvokeGet(&#8217;PasswordLastChanged&#8217;)<br />
  &lt;/GetScriptBlock&gt;<br />
&lt;/ScriptProperty&gt;</p></blockquote>
<p>to work again. I haven&#8217;t tested these definitions thoroughly so YMMV, but if you&#8217;d like to try them out, please help yourself to a <a href="http://pathologicalscripter.wordpress.com/?page_id=8">copy of them</a>. Comments are always welcome also.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pathologicalscripter.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pathologicalscripter.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pathologicalscripter.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pathologicalscripter.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pathologicalscripter.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pathologicalscripter.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pathologicalscripter.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pathologicalscripter.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pathologicalscripter.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pathologicalscripter.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pathologicalscripter.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pathologicalscripter.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=9&subd=pathologicalscripter&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pathologicalscripter.wordpress.com/2006/09/28/i-want-my-directoryentry-methods-back/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2df19fa061166c4f4a848ccc8eacdf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pathologicalscripter</media:title>
		</media:content>
	</item>
		<item>
		<title>Wrappers Revisited</title>
		<link>http://pathologicalscripter.wordpress.com/2006/09/17/wrappers-revisited/</link>
		<comments>http://pathologicalscripter.wordpress.com/2006/09/17/wrappers-revisited/#comments</comments>
		<pubDate>Sun, 17 Sep 2006 16:46:03 +0000</pubDate>
		<dc:creator>pathologicalscripter</dc:creator>
		
		<guid isPermaLink="false">http://pathologicalscripter.wordpress.com/2006/09/17/wrappers-revisited/</guid>
		<description><![CDATA[Yesterday I talked about some &#8220;wrapper&#8221; functions I use to make the .Net 2.0 AD DirectorySearcher and DirectoryEntry classes easier to use. Then I learned from Marc van Orsouw (better known as  /\/\o\/\/) that I was being too verbose in my use of DirectorySearcher. With Marc&#8217;s tips, I could simplify my get-ADEntry function and eliminate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=6&subd=pathologicalscripter&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Yesterday I talked about some <a href="http://pathologicalscripter.wordpress.com/2006/09/16/wrappers/">&#8220;wrapper&#8221; functions</a> I use to make the .Net 2.0 AD DirectorySearcher and DirectoryEntry classes easier to use. Then I learned from Marc van Orsouw (better known as  <a href="http://mow001.blogspot.com/">/\/\o\/\/</a>) that I was being too verbose in my use of DirectorySearcher. With Marc&#8217;s <a href="http://www.blogger.com/comment.g?blogID=18074818&amp;postID=115808884079992534">tips</a>, I could simplify my get-ADEntry function and eliminate the get-UserDN function. (By the way, if you haven&#8217;t visited <a href="http://mow001.blogspot.com/">Marc&#8217;s site</a> recently, you&#8217;re missing some really good Powershell and AD info.)</p>
<p>Instead of</p>
<blockquote><p>$SearchResults = $Searcher.FindOne()<br />
New-Object DirectoryServices.DirectoryEntry (&#8221;LDAP://&#8221; + ($SearchResults.properties.distinguishedname))</p></blockquote>
<p>I could just use</p>
<blockquote><p>$Searcher.FindOne().GetDirectoryEntry()</p></blockquote>
<p>So now my get-ADEntry function looks like this</p>
<blockquote><p>function <strong>get-ADEntry</strong> {<br />
  param ($LdapPath=&#8221;", $samAccount=&#8221;", $Guid=&#8221;", $SmtpAddress=&#8221;")<br />
  $Searcher = New-Object DirectoryServices.DirectorySearcher</p>
<p>  if ($LdapPath -ne &#8220;&#8221;) {<br />
    New-Object DirectoryServices.DirectoryEntry (&#8221;LDAP://&#8221; + $LdapPath)<br />
  }<br />
  elseif ($samAccount -ne &#8220;&#8221;) {<br />
    $Searcher.Filter = &#8220;(&amp;(objectCategory=person)(objectClass=user)(samAccountName=$samAccount))&#8221;<br />
    $Searcher.FindOne().GetDirectoryEntry()<br />
  }<br />
  elseif ($SmtpAddress -ne &#8220;&#8221;) {<br />
    $Searcher.Filter = &#8220;(&amp;(objectCategory=person)(objectClass=user)(proxyaddresses=smtp:$SmtpAddress))&#8221;<br />
    $Searcher.FindOne().GetDirectoryEntry()<br />
  }<br />
  elseif ($Guid -ne &#8220;&#8221;) {<br />
    New-Object DirectoryServices.DirectoryEntry (&#8221;<a href="//&lt;GUID">LDAP://&lt;GUID</a>=&#8221; + (get-NativeGuid $Guid) + &#8220;&gt;&#8221;)<br />
  }<br />
  else {<br />
    New-Object DirectoryServices.DirectoryEntry<br />
  }<br />
}</p></blockquote>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pathologicalscripter.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pathologicalscripter.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pathologicalscripter.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pathologicalscripter.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pathologicalscripter.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pathologicalscripter.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pathologicalscripter.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pathologicalscripter.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pathologicalscripter.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pathologicalscripter.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pathologicalscripter.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pathologicalscripter.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=6&subd=pathologicalscripter&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pathologicalscripter.wordpress.com/2006/09/17/wrappers-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2df19fa061166c4f4a848ccc8eacdf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pathologicalscripter</media:title>
		</media:content>
	</item>
		<item>
		<title>ScriptMethods</title>
		<link>http://pathologicalscripter.wordpress.com/2006/09/16/scriptmethods/</link>
		<comments>http://pathologicalscripter.wordpress.com/2006/09/16/scriptmethods/#comments</comments>
		<pubDate>Sat, 16 Sep 2006 20:55:37 +0000</pubDate>
		<dc:creator>pathologicalscripter</dc:creator>
		
		<guid isPermaLink="false">http://pathologicalscripter.wordpress.com/2006/09/16/scriptmethods/</guid>
		<description><![CDATA[I&#8217;ve always liked extensible languages like Perl so I&#8217;m enjoying PowerShell&#8217;s type extensibility. I&#8217;ve added several script methods or properties written by other people to my standard setup. After writing about how I had added a function to my profile.ps1 file which would convert a Guid string to &#8220;native&#8221; format, it occurred to me that I could just add that as a method [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=5&subd=pathologicalscripter&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve always liked extensible languages like Perl so I&#8217;m enjoying PowerShell&#8217;s type extensibility. I&#8217;ve added several script methods or properties written by other people to my standard setup. After writing about how I had added a function to my profile.ps1 file which would convert a Guid string to &#8220;native&#8221; format, it occurred to me that I could just add that as a method to the system.guid type definition. So I added this to my <em>My.Types.Ps1xml</em> file:</p>
<blockquote><p>&lt;Type&gt;<br />
  &lt;Name&gt;System.Guid&lt;/Name&gt;<br />
  &lt;Members&gt;<br />
    &lt;ScriptMethod&gt;<br />
      &lt;Name&gt;ToNativeString&lt;/Name&gt;<br />
      &lt;Script&gt;<br />
        $local:NativeGuid = &#8220;&#8221;<br />
        $this.ToByteArray() | foreach { $NativeGuid +=  $_.tostring(&#8221;x2&#8243;) }<br />
        $NativeGuid<br />
      &lt;/Script&gt;<br />
    &lt;/ScriptMethod&gt;<br />
  &lt;/Members&gt;<br />
&lt;/Type&gt;</p></blockquote>
<p> Now I can use that method like this:</p>
<blockquote><p>PS&gt;$Guid = new-object system.guid (&#8221;4c5efbc3-a504-4cda-8cc7-1211ad502c60&#8243;)<br />
PS&gt;$Guid|gm</p>
<p>   TypeName: System.Guid</p>
<p>Name           MemberType   Definition<br />
&#8212;-           &#8212;&#8212;&#8212;-   &#8212;&#8212;&#8212;-<br />
CompareTo      Method       System.Int32 CompareTo(Object value), System.Int32 CompareTo(Guid value)<br />
Equals         Method       System.Boolean Equals(Object o), System.Boolean Equals(Guid g)<br />
GetHashCode    Method       System.Int32 GetHashCode()<br />
GetType        Method       System.Type GetType()<br />
ToByteArray    Method       System.Byte[] ToByteArray()<br />
ToString       Method       System.String ToString(), System.String ToString(String format), System.String ToString(&#8230;<br />
MSDN           ScriptMethod System.Object MSDN();<br />
ToNativeString ScriptMethod System.Object ToNativeString();<br />
PS&gt;$Guid.ToNativeString()<br />
c3fb5e4c04a5da4c8cc71211ad502c60</p></blockquote>
<p>And my function becomes  this:</p>
<blockquote><p>function get-NativeGuid {<br />
  param ($GuidString)<br />
  (new-object system.guid ($GuidString)).ToNativeString()<br />
}</p></blockquote>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pathologicalscripter.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pathologicalscripter.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pathologicalscripter.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pathologicalscripter.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pathologicalscripter.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pathologicalscripter.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pathologicalscripter.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pathologicalscripter.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pathologicalscripter.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pathologicalscripter.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pathologicalscripter.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pathologicalscripter.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=5&subd=pathologicalscripter&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pathologicalscripter.wordpress.com/2006/09/16/scriptmethods/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2df19fa061166c4f4a848ccc8eacdf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pathologicalscripter</media:title>
		</media:content>
	</item>
		<item>
		<title>Wrappers</title>
		<link>http://pathologicalscripter.wordpress.com/2006/09/16/wrappers/</link>
		<comments>http://pathologicalscripter.wordpress.com/2006/09/16/wrappers/#comments</comments>
		<pubDate>Sat, 16 Sep 2006 16:22:02 +0000</pubDate>
		<dc:creator>pathologicalscripter</dc:creator>
		
		<guid isPermaLink="false">http://pathologicalscripter.wordpress.com/2006/09/16/wrappers/</guid>
		<description><![CDATA[I&#8217;ve been using PowerShell to explore Active Directory. Since I do most of my exploring from the command line and I&#8217;m inherently lazy, I&#8217;ve been creating &#8220;wrappers&#8221; for some .Net 2.0 AD stuff to add to my profile.ps1 file. (&#8221;The fewer keystrokes, the better&#8221; is my motto.) I started with the DirectorySearcher by creating a function [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=4&subd=pathologicalscripter&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been using PowerShell to explore Active Directory. Since I do most of my exploring from the command line and I&#8217;m inherently lazy, I&#8217;ve been creating &#8220;wrappers&#8221; for some .Net 2.0 AD stuff to add to my profile.ps1 file. (&#8221;The fewer keystrokes, the better&#8221; is my motto.) I started with the DirectorySearcher by creating a function &#8220;new-ADSearcher&#8221;.</p>
<p>I was always using the same &#8220;preamble&#8221; of setting the CacheResults, SearchScope and PageSize so at least I could get rid of typing those all the time. (Yeah, I know that those values for CacheResults and SearchScope are the PS defaults, but I don&#8217;t like to have to depend on defaults. So call me OCD.)</p>
<p>The Filter and SearchRoot attributes of the DirectorySearcher were the main things I seemed to be using so they became the parameters for the function. But since the SearchRoot attribute actually required a DirectoryEntry object, that lead to a separate function named (predictably enough) &#8220;get-ADEntry&#8221;.</p>
<p>get-ADEntry originally only had a single optional parameter of LdapPath, which met the need for the new-ADSearcher function. But I was also frequently needing to access user objects based on their sAMAccountName attribute, as well as other AD objects based on their objectGuid attribute. So get-ADEntry grew a little with the addition of the samAccount and Guid parameters. And now I needed two additional functions, get-UserDN and get-NativeGuid.</p>
<p>get-UserDN was pretty straightforward. All I needed to do was use new-ADSearcher with the appropriate filter. (Did I mention that I was lazy?) Of course, after I wrote get-UserDN, I found myself searching for users by their SMTP address so I just added this to get-USerDN also. (And now I can go back and add that as an option to get-ADEntry also since it&#8217;ll just need to call get-UserDN.)</p>
<p>get-NativeGuid was needed because GUIDs are IMHO weird things. By definition a GUID is a 128-bit integer (16 bytes). The most common representation that you seem to see is in the form &#8220;e1c9f329-a5c2-46c0-b900-ee8e4e3ebbf6&#8243;. But to search for a GUID in an LDAP filter in PowerShell with DirectorySearcher object, you seem to need to use the form &#8220;29f3c9e1c2a5c046b900ee8e4e3ebbf6&#8243; which is the form that you&#8217;ll get from the get_NativeGuid() method of a DirectoryEntry object in PowerShell. (I say &#8220;seem to need&#8221; because I can&#8217;t find this documented anywhere.) Unfortunately, the system.guid class.tostring formatting options don&#8217;t seem to provide this conversion so this function was needed.</p>
<p>Disclaimer: Since I primarily work in a single domain, single forest environment, these functions might have issues in a multi-domain forest. And I haven&#8217;t spent any time adding error-checking or usability features. (Did I mention that I was lazy?)</p>
<blockquote><p>function <strong>new-ADSearcher</strong> {<br />
  param ($Filter=&#8221;",$Root=&#8221;")<br />
  $local:Searcher = New-Object DirectoryServices.DirectorySearcher<br />
  $Searcher.CacheResults = $true<br />
  $Searcher.SearchScope = &#8220;Subtree&#8221;<br />
  $Searcher.PageSize = 1000<br />
  if ($Filter -ne &#8220;&#8221;) { $Searcher.Filter = $Filter }<br />
  if ($Root -ne &#8220;&#8221;) { $Searcher.SearchRoot = get-ADEntry -ldappath $Root }<br />
  $Searcher<br />
}</p></blockquote>
<blockquote><p>function <strong>get-ADEntry</strong> {<br />
  param ($LdapPath=&#8221;", $samAccount=&#8221;", $Guid=&#8221;", $SmtpAddress=&#8221;")<br />
  if ($LdapPath -ne &#8220;&#8221;) {<br />
    New-Object DirectoryServices.DirectoryEntry (&#8221;LDAP://&#8221; + $LdapPath)<br />
  }<br />
  elseif ($samAccount -ne &#8220;&#8221;) {<br />
    New-Object DirectoryServices.DirectoryEntry (&#8221;LDAP://&#8221; + (get-userDN -samAccount $samAccount))<br />
  }<br />
  elseif ($SmtpAddress -ne &#8220;&#8221;) {<br />
    New-Object DirectoryServices.DirectoryEntry (&#8221;LDAP://&#8221; + (get-userDN -SmtpAddress $SmtpAddress))<br />
  }<br />
  elseif ($Guid -ne &#8220;&#8221;) {<br />
    New-Object DirectoryServices.DirectoryEntry (&#8221;<a href="//&lt;GUID/">LDAP://&lt;GUID</a>=&#8221; + (get-NativeGuid $Guid) + &#8220;&gt;&#8221;)<br />
  }<br />
  else {<br />
    New-Object DirectoryServices.DirectoryEntry<br />
  }<br />
}</p></blockquote>
<blockquote><p>function <strong>get-UserDN</strong> {<br />
  param ($samAccount = &#8220;&#8221;, $SmtpAddress = &#8220;&#8221;)<br />
  $local:Filter = &#8220;&#8221;<br />
  if ($samAccount -ne &#8220;&#8221;) {<br />
    $Filter = &#8220;(&amp;(objectCategory=person)(objectClass=user)(samAccountName=&#8221; + $samAccount + &#8220;))&#8221;<br />
  }<br />
  elseif ($SmtpAddress -ne &#8220;&#8221;) {<br />
    $Filter = &#8220;(&amp;(objectCategory=person)(objectClass=user)(mailnickname=*)(proxyaddresses=smtp:&#8221; + $SmtpAddress + &#8220;))&#8221;<br />
  }<br />
  $local:Searcher = new-ADSearcher -filter $Filter<br />
  $local:SearchResults = $Searcher.FindOne()<br />
  $SearchResults.properties.distinguishedname<br />
}</p></blockquote>
<blockquote><p>function <strong>get-NativeGuid</strong> {<br />
  param ($GuidString)<br />
  $local:Guid = new-object system.guid ($GuidString)<br />
  $local:NativeGuid = &#8220;&#8221;<br />
  $Guid.ToByteArray() | foreach { $NativeGuid +=  $_.tostring(&#8221;x2&#8243;) }<br />
  $NativeGuid<br />
}</p></blockquote>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pathologicalscripter.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pathologicalscripter.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pathologicalscripter.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pathologicalscripter.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pathologicalscripter.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pathologicalscripter.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pathologicalscripter.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pathologicalscripter.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pathologicalscripter.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pathologicalscripter.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pathologicalscripter.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pathologicalscripter.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=4&subd=pathologicalscripter&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pathologicalscripter.wordpress.com/2006/09/16/wrappers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2df19fa061166c4f4a848ccc8eacdf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pathologicalscripter</media:title>
		</media:content>
	</item>
		<item>
		<title>Hello world!</title>
		<link>http://pathologicalscripter.wordpress.com/2006/06/19/hello-world/</link>
		<comments>http://pathologicalscripter.wordpress.com/2006/06/19/hello-world/#comments</comments>
		<pubDate>Mon, 19 Jun 2006 01:40:51 +0000</pubDate>
		<dc:creator>pathologicalscripter</dc:creator>
				<category><![CDATA[PowerShell Resources]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Welcome to the Pathological Scripter.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=1&subd=pathologicalscripter&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Welcome to the <a href="http://pathologicalscripter.wordpress.com">Pathological Scripter</a>.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pathologicalscripter.wordpress.com/1/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pathologicalscripter.wordpress.com/1/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pathologicalscripter.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pathologicalscripter.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pathologicalscripter.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pathologicalscripter.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pathologicalscripter.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pathologicalscripter.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pathologicalscripter.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pathologicalscripter.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pathologicalscripter.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pathologicalscripter.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pathologicalscripter.wordpress.com&blog=271908&post=1&subd=pathologicalscripter&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pathologicalscripter.wordpress.com/2006/06/19/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2df19fa061166c4f4a848ccc8eacdf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pathologicalscripter</media:title>
		</media:content>
	</item>
	</channel>
</rss>