<?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>vmweaver.com</title>
	<atom:link href="http://vmweaver.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://vmweaver.com</link>
	<description>Mindless ramblings of a geek...</description>
	<lastBuildDate>Thu, 06 Oct 2011 20:42:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Oooey-GUI Script Searcher</title>
		<link>http://vmweaver.com/index.php/2011/10/oooey-gui-script-searcher/</link>
		<comments>http://vmweaver.com/index.php/2011/10/oooey-gui-script-searcher/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 20:40:39 +0000</pubDate>
		<dc:creator>Mark A. Weaver</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://vmweaver.com/?p=290</guid>
		<description><![CDATA[As a follow up to my Script Tagging post, I have put together a Powershell GUI script that one can use to search a folder structure that has tagged scripts in it. I haven&#8217;t documented this as well as I normally would, so perhaps that will come at a later time. Basically you launch it [...]]]></description>
			<content:encoded><![CDATA[<p>As a follow up to my <a href="http://vmweaver.com/index.php/2011/07/tag-youre-it/">Script Tagging post</a>, I have put together a Powershell GUI script that one can use to search a folder structure that has tagged scripts in it.</p>
<p>I haven&#8217;t documented this as well as I normally would, so perhaps that will come at a later time.</p>
<p>Basically you launch it and the &#8220;Folder Root&#8221; will default to the current directory.</p>
<p>Once you enter some values in the text boxes, and &#8220;Execute&#8221; the search, the script will recursively interrogate all powershell scripts in the root folder and all child folders looking for the appropriate tags as created by the &#8220;Tagging&#8221; post.</p>
<p><img src="http://vmweaver.com/wp-content/uploads/2011/10/ScriptSearchGUI.png" alt="UI ScreenShot" /></p>
<p>I hope you find it helpful and here is the code!<br />
As always&#8230; Happy scripting!!!<br />
 &#8212; Mark</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> Find<span style="color: pink;">-</span>Script
<span style="color: #000000;">&#123;</span>
<span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Term</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;/*&quot;</span> <span style="color: pink;">,</span><span style="color: #800080;">$Path</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;.\&quot;</span><span style="color: pink;">,</span><span style="color: #800080;">$FilePattern</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;*.ps1&quot;</span><span style="color: pink;">,</span><span style="color: #800080;">$Tag</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;/*&quot;</span><span style="color: pink;">,</span> <span style="color: #800080;">$Auth</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;/*&quot;</span><span style="color: pink;">,</span> <span style="color: #800080;">$Desc</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;/*&quot;</span><span style="color: pink;">,</span> <span style="color: #800080;">$Misc</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;/*&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$AllScripts</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-ChildItem</span> <span style="color: pink;">*</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$Path</span> <span style="color: #008080; font-style: italic;">-include</span> <span style="color: #800080;">$FilePattern</span> <span style="color: #008080; font-style: italic;">-recurse</span>
<span style="color: #000000;">&#91;</span><span style="color: #008080;">array</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$AllTags</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Null</span>
<span style="color: #000000;">&#91;</span><span style="color: #008080;">array</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$FoundScripts</span><span style="color: pink;">=</span><span style="color: #800080;">$null</span>
<span style="color: #0000FF;">Foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Script</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$AllScripts</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #800080;">$Contents</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800080;">$Script</span>
  <span style="color: #000000;">&#91;</span><span style="color: #008080;">array</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$AllTags</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Null</span>
  <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Contents</span> <span style="color: #FF0000;">-imatch</span> <span style="color: #800000;">&quot;_BEGINMARKUP&quot;</span><span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
    <span style="color: #008000;"># ($Contents -imatch &quot;_TAG:&quot;).gettype()</span>
	<span style="color: #800080;">$Found</span> <span style="color: pink;">=</span> <span style="color: #800080;">$False</span>
     <span style="color: #800080;">$Tags</span> <span style="color: pink;">=</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: #000000;">&#40;</span><span style="color: #800080;">$Contents</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;_TAG:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;#&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	 <span style="color: #800080;">$Author</span><span style="color: pink;">=</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: #000000;">&#40;</span><span style="color: #800080;">$Contents</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;_AUTH:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;#&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
     <span style="color: #800080;">$Description</span> <span style="color: pink;">=</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: #000000;">&#40;</span><span style="color: #800080;">$Contents</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;_DESC:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;#&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	 <span style="color: #800080;">$Version</span> <span style="color: pink;">=</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: #000000;">&#40;</span><span style="color: #800080;">$Contents</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;_VER:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;#&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	 <span style="color: #800080;">$Miscellaneous</span> <span style="color: pink;">=</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: #000000;">&#40;</span><span style="color: #800080;">$Contents</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;_MISC:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;#&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	 <span style="color: #800080;">$ModifiedDate</span> <span style="color: pink;">=</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: #000000;">&#40;</span><span style="color: #800080;">$Contents</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;_DATE:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;#&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	 <span style="color: #800080;">$AllTags</span> <span style="color: pink;">+=</span><span style="color: #800080;">$Tags</span>
	 <span style="color: #800080;">$AllTags</span> <span style="color: pink;">+=</span><span style="color: #800080;">$Author</span>
	 <span style="color: #800080;">$AllTags</span> <span style="color: pink;">+=</span><span style="color: #800080;">$Description</span>
	 <span style="color: #800080;">$AllTags</span> <span style="color: pink;">+=</span><span style="color: #800080;">$Version</span>
	 <span style="color: #800080;">$AllTags</span> <span style="color: pink;">+=</span><span style="color: #800080;">$Miscellaneous</span>
&nbsp;
	<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Tags</span> <span style="color: #FF0000;">-imatch</span> <span style="color: #800080;">$Tag</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Author</span> <span style="color: #FF0000;">-imatch</span> <span style="color: #800080;">$Auth</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Description</span> <span style="color: #FF0000;">-imatch</span> <span style="color: #800080;">$Desc</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Miscellaneous</span> <span style="color: #FF0000;">-imatch</span> <span style="color: #800080;">$Misc</span><span style="color: #000000;">&#41;</span><span style="color: #FF0000;">-and</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$AllTags</span> <span style="color: #FF0000;">-imatch</span> <span style="color: #800080;">$Term</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Found</span> <span style="color: pink;">=</span> <span style="color: #800080;">$True</span><span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Found</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;">$FoundItem</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> Script<span style="color: pink;">,</span>Author<span style="color: pink;">,</span>LastModified<span style="color: pink;">,</span>Tags<span style="color: pink;">,</span>Description
	  <span style="color: #800080;">$FoundItem</span>.Script <span style="color: pink;">=</span> <span style="color: #800080;">$Script</span>
	  <span style="color: #800080;">$FoundITem</span>.Author <span style="color: pink;">=</span> <span style="color: #800080;">$Author</span>
	  <span style="color: #800080;">$FoundItem</span>.LastModified <span style="color: pink;">=</span> <span style="color: #800080;">$Script</span>.LastWriteTime
	  <span style="color: #800080;">$FoundItem</span>.Tags <span style="color: pink;">=</span> <span style="color: #800080;">$Tags</span>
	  <span style="color: #800080;">$FoundItem</span>.Description <span style="color: pink;">=</span> <span style="color: #800080;">$Description</span>
	  <span style="color: #800080;">$FoundScripts</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$FoundItem</span>
	<span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$FoundScripts</span> <span style="color: #FF0000;">-ne</span> <span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
 <span style="color: #008000;"># Write-Host &quot;Search Term: $Term&quot;</span>
 <span style="color: #0000FF;">return</span> <span style="color: #800080;">$FoundScripts</span>
  <span style="color: #000000;">&#125;</span>
  <span style="color: #0000FF;">else</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;No Scripts found with specified criteria.&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Yellow
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #008000;">#Generated Form Function</span>
<span style="color: #0000FF;">function</span> GenerateForm <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #008000;">#region Import the Assemblies</span>
<span style="color: #000000;">&#91;</span>reflection.assembly<span style="color: #000000;">&#93;</span>::loadwithpartialname<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>
<span style="color: #000000;">&#91;</span>reflection.assembly<span style="color: #000000;">&#93;</span>::loadwithpartialname<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;System.Drawing&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>
<span style="color: #008000;">#endregion</span>
&nbsp;
<span style="color: #008000;">#region Generated Form Objects</span>
<span style="color: #800080;">$form1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.Form
<span style="color: #800080;">$btnBrowse</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.Button
<span style="color: #800080;">$txtPath</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.TextBox
<span style="color: #800080;">$button1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.Button
<span style="color: #800080;">$label5</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.Label
<span style="color: #800080;">$label4</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.Label
<span style="color: #800080;">$label3</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.Label
<span style="color: #800080;">$label2</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.Label
<span style="color: #800080;">$label1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.Label
<span style="color: #800080;">$label6</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.Label
<span style="color: #800080;">$txtTag</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.TextBox
<span style="color: #800080;">$txtMisc</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.TextBox
<span style="color: #800080;">$txtAuth</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.TextBox
<span style="color: #800080;">$fldBrowser</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.FolderBrowserDialog
<span style="color: #800080;">$txtDesc</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.TextBox
<span style="color: #800080;">$textBox2</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.TextBox
<span style="color: #800080;">$txtTerm</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.TextBox
<span style="color: #800080;">$dataGridView1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.DataGridView
<span style="color: #800080;">$InitialFormWindowState</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Windows.Forms.FormWindowState
<span style="color: #008000;">#endregion Generated Form Objects</span>
&nbsp;
<span style="color: #008000;">#----------------------------------------------</span>
<span style="color: #008000;">#Generated Event Script Blocks</span>
<span style="color: #008000;">#----------------------------------------------</span>
<span style="color: #008000;">#Provide Custom Code for events specified in PrimalForms.</span>
<span style="color: #800080;">$button1_OnClick</span><span style="color: pink;">=</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #008000;">#TODO: Place custom script here</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$txtPath</span>.text <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$fldBrowser</span>.ShowDialog<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$txtPath</span>.Text <span style="color: pink;">=</span> <span style="color: #800080;">$fldBrowser</span>.SelectedPath
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$txtAuth</span>.Text <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Auth</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;/*&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #0000FF;">else</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Auth</span> <span style="color: pink;">=</span> <span style="color: #800080;">$txtAuth</span>.Text.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$txtTag</span>.Text <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Tags</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;/*&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #0000FF;">else</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Tags</span> <span style="color: pink;">=</span> <span style="color: #800080;">$txtTag</span>.Text.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$txtMisc</span>.Text <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Misc</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;/*&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #0000FF;">else</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Misc</span> <span style="color: pink;">=</span> <span style="color: #800080;">$txtMisc</span>.Text.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$txtTerm</span>.Text <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Term</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;/*&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #0000FF;">else</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Term</span> <span style="color: pink;">=</span> <span style="color: #800080;">$txtTerm</span>.Text.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$txtDesc</span>.Text <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Desc</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;/*&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #0000FF;">else</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Desc</span> <span style="color: pink;">=</span> <span style="color: #800080;">$txtDesc</span>.Text.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;">#Write-Host ($txtAuth.Text -eq &quot;&quot;)</span>
<span style="color: #800080;">$Path</span> <span style="color: pink;">=</span> <span style="color: #800080;">$txtPath</span>.Text
<span style="color: #008000;">#Write-Host &quot;find-script -Path &quot;&quot;$Path&quot;&quot; -Auth $Auth -Desc $Desc -Misc $Misc -Tag $Tags -Term $Term&quot;</span>
&nbsp;
<span style="color: #800080;">$FoundScripts</span> <span style="color: pink;">=</span> find<span style="color: pink;">-</span>script <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800000;">&quot;$Path&quot;</span> <span style="color: pink;">-</span>Auth <span style="color: #800000;">&quot;$Auth&quot;</span> <span style="color: pink;">-</span>Desc <span style="color: #800000;">&quot;$Desc&quot;</span> <span style="color: pink;">-</span>Misc <span style="color: #800000;">&quot;$Misc&quot;</span> <span style="color: pink;">-</span>Tag <span style="color: #800000;">&quot;$Tags&quot;</span> <span style="color: pink;">-</span>Term <span style="color: #800000;">&quot;$Term&quot;</span>
<span style="color: #800080;">$array</span><span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> System.Collections.ArrayList
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$FoundScripts</span>.count <span style="color: #FF0000;">-gt</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$array</span>.addrange<span style="color: #000000;">&#40;</span><span style="color: #800080;">$FoundScripts</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">else</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$array</span>.add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$FoundScripts</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
    <span style="color: #800080;">$dataGridview1</span>.datasource <span style="color: pink;">=</span> <span style="color: #800080;">$array</span>
    <span style="color: #800080;">$form1</span>.refresh<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> 
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #800080;">$dataGridView1_Selectionchanged</span> <span style="color: pink;">=</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #800080;">$f</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>
   <span style="color: #800080;">$SelectedPath</span> <span style="color: pink;">=</span> <span style="color: #800080;">$datagridview1</span>.selectedcells<span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>.value
   <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$SelectedPath</span> <span style="color: #FF0000;">-ne</span> <span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
   <span style="color: #800080;">$f</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800080;">$SelectedPath</span>
   <span style="color: #000000;">&#125;</span>
   <span style="color: #800080;">$textBox2</span>.lines <span style="color: pink;">=</span><span style="color: #800080;">$f</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$btnBrowse_OnClick</span><span style="color: pink;">=</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$object</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #008080; font-style: italic;">-comObject</span> Shell.Application  
&nbsp;
    <span style="color: #800080;">$folder</span> <span style="color: pink;">=</span> <span style="color: #800080;">$object</span>.BrowseForFolder<span style="color: #000000;">&#40;</span><span style="color: #804000;">0</span><span style="color: pink;">,</span> <span style="color: #800080;">$message</span><span style="color: pink;">,</span> <span style="color: #804000;">0</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$folder</span> <span style="color: #FF0000;">-ne</span> <span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> 
&nbsp;
<span style="color: #800080;">$txtPath</span>.Text <span style="color: pink;">=</span> <span style="color: #800080;">$folder</span>.self.Path
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #800080;">$handler_form1_Load</span><span style="color: pink;">=</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #008000;">#TODO: Place custom script here</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #800080;">$OnLoadForm_StateCorrection</span><span style="color: pink;">=</span>
<span style="color: #000000;">&#123;</span><span style="color: #008000;">#Correct the initial state of the form to prevent the .Net maximized form issue</span>
	<span style="color: #800080;">$form1</span>.WindowState <span style="color: pink;">=</span> <span style="color: #800080;">$InitialFormWindowState</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;">#----------------------------------------------</span>
<span style="color: #008000;">#region Generated Form Code</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">650</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">1050</span>
<span style="color: #800080;">$form1</span>.ClientSize <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$form1</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
<span style="color: #800080;">$form1</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;form1&quot;</span>
<span style="color: #800080;">$form1</span>.Text <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Script Search Interface&quot;</span>
<span style="color: #800080;">$form1</span>.add_Load<span style="color: #000000;">&#40;</span><span style="color: #800080;">$handler_form1_Load</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$button1</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">900</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">35</span>
<span style="color: #800080;">$button1</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$button1</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;button1&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">23</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">100</span>
<span style="color: #800080;">$button1</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$button1</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">2</span>
<span style="color: #800080;">$button1</span>.Text <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Execute Search&quot;</span>
<span style="color: #800080;">$button1</span>.UseVisualStyleBackColor <span style="color: pink;">=</span> <span style="color: #800080;">$True</span>
<span style="color: #800080;">$button1</span>.add_Click<span style="color: #000000;">&#40;</span><span style="color: #800080;">$button1_OnClick</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$button1</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$btnBrowse</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">259</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">36</span>
<span style="color: #800080;">$btnBrowse</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$btnBrowse</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;btnBrowse&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">23</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">60</span>
<span style="color: #800080;">$btnBrowse</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$btnBrowse</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">14</span>
<span style="color: #800080;">$btnBrowse</span>.Text <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Browse...&quot;</span>
<span style="color: #800080;">$btnBrowse</span>.UseVisualStyleBackColor <span style="color: pink;">=</span> <span style="color: #800080;">$True</span>
<span style="color: #800080;">$btnBrowse</span>.add_Click<span style="color: #000000;">&#40;</span><span style="color: #800080;">$btnBrowse_OnClick</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$btnBrowse</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$txtPath</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">12</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">38</span>
<span style="color: #800080;">$txtPath</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$txtPath</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;txtPath&quot;</span>
<span style="color: #800080;">$txtPath</span>.Text <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Location</span><span style="color: #000000;">&#41;</span>.Path
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">20</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">241</span>
<span style="color: #800080;">$txtPath</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$txtPath</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">13</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$txtPath</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$fldBrowser</span>.RootFolder <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Environment<span style="color: pink;">+</span>SpecialFolder<span style="color: #000000;">&#93;</span>::Personal
&nbsp;
<span style="color: #800080;">$dataGridView1</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">12</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">80</span>
<span style="color: #800080;">$dataGridView1</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$dataGridView1</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;dataGridView1&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">218</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">1000</span>
<span style="color: #800080;">$dataGridView1</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$dataGridView1</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
<span style="color: #800080;">$dataGridView1</span>.Autosizecolumnsmode<span style="color: pink;">=</span><span style="color: #800000;">&quot;AllCells&quot;</span>
<span style="color: #800080;">$dataGridView1</span>.SelectionMode <span style="color: pink;">=</span> <span style="color: #804000;">1</span>
<span style="color: #800080;">$dataGridView1</span>.Readonly <span style="color: pink;">=</span> <span style="color: #800080;">$True</span>
<span style="color: #800080;">$dataGridView1</span>.add_SelectionChanged<span style="color: #000000;">&#40;</span><span style="color: #800080;">$dataGridView1_Selectionchanged</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$dataGridView1</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$textBox2</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">12</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">300</span>
<span style="color: #800080;">$textBox2</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$textBox2</span>.Multiline <span style="color: pink;">=</span> <span style="color: #800080;">$True</span>
<span style="color: #800080;">$textBox2</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;textBox2&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">350</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">1000</span>
<span style="color: #800080;">$textBox2</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$textBox2</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">3</span>
<span style="color: #800080;">$textbox2</span>.scrollbars <span style="color: pink;">=</span> <span style="color: #804000;">3</span>
<span style="color: #800080;">$textBox2</span>.Readonly<span style="color: pink;">=</span><span style="color: #800080;">$true</span>
<span style="color: #800080;">$textBox2</span>.wordwrap <span style="color: pink;">=</span> <span style="color: #800080;">$False</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$textBox2</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$label5</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">703</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">38</span>
<span style="color: #800080;">$label5</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$label5</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;label5&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">17</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">46</span>
<span style="color: #800080;">$label5</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$label5</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">12</span>
<span style="color: #800080;">$label5</span>.Text <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Misc:&quot;</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$label5</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$label6</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">12</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">12</span>
<span style="color: #800080;">$label6</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$label6</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;label6&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">17</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">200</span>
<span style="color: #800080;">$label6</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$label6</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">13</span>
<span style="color: #800080;">$label6</span>.Text <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Search Folder Root:&quot;</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$label6</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$label4</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span><span style="color: #804000;">703</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">15</span>
<span style="color: #800080;">$label4</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$label4</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;label4&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">20</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">46</span>
<span style="color: #800080;">$label4</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$label4</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">11</span>
<span style="color: #800080;">$label4</span>.Text <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Tags:&quot;</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$label4</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$label3</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">484</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">41</span>
<span style="color: #800080;">$label3</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$label3</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;label3&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">23</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">64</span>
<span style="color: #800080;">$label3</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$label3</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">10</span>
<span style="color: #800080;">$label3</span>.Text <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Description:&quot;</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$label3</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>System.Environment<span style="color: pink;">+</span>SpecialFolder<span style="color: #000000;">&#93;</span><span style="color: #800080;">$SearchRoot</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;MyDocuments&quot;</span>
<span style="color: #800080;">$fldBrowser</span>.RootFolder <span style="color: pink;">=</span> <span style="color: #800080;">$SearchRoot</span>
&nbsp;
<span style="color: #800080;">$label2</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">507</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">12</span>
<span style="color: #800080;">$label2</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$label2</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;label2&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">20</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">41</span>
<span style="color: #800080;">$label2</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$label2</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">9</span>
<span style="color: #800080;">$label2</span>.Text <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Author:&quot;</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$label2</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$label1</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">310</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">15</span>
<span style="color: #800080;">$label1</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$label1</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;label1&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">23</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">60</span>
<span style="color: #800080;">$label1</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$label1</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">8</span>
<span style="color: #800080;">$label1</span>.Text <span style="color: pink;">=</span> <span style="color: #800000;">&quot;All Fields:&quot;</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$label1</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$txtTag</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span><span style="color: #804000;">755</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">12</span>
<span style="color: #800080;">$txtTag</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$txtTag</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;txtTag&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">20</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">100</span>
<span style="color: #800080;">$txtTag</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$txtTag</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">7</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$txtTag</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$txtMisc</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">755</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">35</span>
<span style="color: #800080;">$txtMisc</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$txtMisc</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;txtMisc&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">20</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">100</span>
<span style="color: #800080;">$txtMisc</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$txtMisc</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">6</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$txtMisc</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$txtAuth</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">554</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">12</span>
<span style="color: #800080;">$txtAuth</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$txtAuth</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;txtAuth&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">20</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">100</span>
<span style="color: #800080;">$txtAuth</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$txtAuth</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">5</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$txtAuth</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$txtDesc</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">554</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">38</span>
<span style="color: #800080;">$txtDesc</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$txtDesc</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;txtDesc&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">20</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">100</span>
<span style="color: #800080;">$txtDesc</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$txtDesc</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">4</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$txtDesc</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$txtTerm</span>.DataBindings.DefaultDataSourceUpdateMode <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
<span style="color: #800080;">$System_Drawing_Point</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Point
<span style="color: #800080;">$System_Drawing_Point</span>.X <span style="color: pink;">=</span> <span style="color: #804000;">374</span>
<span style="color: #800080;">$System_Drawing_Point</span>.Y <span style="color: pink;">=</span> <span style="color: #804000;">12</span>
<span style="color: #800080;">$txtTerm</span>.Location <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Point</span>
<span style="color: #800080;">$txtTerm</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;txtTerm&quot;</span>
<span style="color: #800080;">$System_Drawing_Size</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Drawing.Size
<span style="color: #800080;">$System_Drawing_Size</span>.Height <span style="color: pink;">=</span> <span style="color: #804000;">20</span>
<span style="color: #800080;">$System_Drawing_Size</span>.Width <span style="color: pink;">=</span> <span style="color: #804000;">100</span>
<span style="color: #800080;">$txtTerm</span>.Size <span style="color: pink;">=</span> <span style="color: #800080;">$System_Drawing_Size</span>
<span style="color: #800080;">$txtTerm</span>.TabIndex <span style="color: pink;">=</span> <span style="color: #804000;">1</span>
&nbsp;
<span style="color: #800080;">$form1</span>.Controls.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$txtTerm</span><span style="color: #000000;">&#41;</span>
<span style="color: #008000;">#endregion Generated Form Code</span>
&nbsp;
<span style="color: #008000;">#Save the initial state of the form</span>
<span style="color: #800080;">$InitialFormWindowState</span> <span style="color: pink;">=</span> <span style="color: #800080;">$form1</span>.WindowState
<span style="color: #008000;">#Init the OnLoad event to correct the initial state of the form</span>
<span style="color: #800080;">$form1</span>.add_Load<span style="color: #000000;">&#40;</span><span style="color: #800080;">$OnLoadForm_StateCorrection</span><span style="color: #000000;">&#41;</span>
<span style="color: #008000;">#Show the Form</span>
<span style="color: #800080;">$form1</span>.ShowDialog<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>
&nbsp;
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#End Function</span>
&nbsp;
<span style="color: #008000;">#Call the Function</span>
GenerateForm</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://vmweaver.com/index.php/2011/10/oooey-gui-script-searcher/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell 3.0 &#8211; drool</title>
		<link>http://vmweaver.com/index.php/2011/09/powershell-3-0-drool/</link>
		<comments>http://vmweaver.com/index.php/2011/09/powershell-3-0-drool/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 03:09:20 +0000</pubDate>
		<dc:creator>Mark A. Weaver</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://vmweaver.com/?p=272</guid>
		<description><![CDATA[Okay, so if you live under a rock and haven&#8217;t heard, the CTP for the Windows Management Framework 3.0 has been released by Microsoft (http://www.microsoft.com/download/en/details.aspx?id=27548). I know, you are probably thinking &#8220;Big Deal!!&#8221; another Community Tech Preview. Not so fast there&#8230; THIS CTP includes Powershell 3.0! Let me restate: &#8220;THIS CTP INCLUDES POWERSHELL 3.0!&#8221; What [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, so if you live under a rock and haven&#8217;t heard, the CTP for the Windows Management Framework 3.0 has been released by Microsoft (<a href="http://www.microsoft.com/download/en/details.aspx?id=27548">http://www.microsoft.com/download/en/details.aspx?id=27548</a>).</p>
<p>I know, you are probably thinking &#8220;Big Deal!!&#8221; another Community Tech Preview.  Not so fast there&#8230; THIS CTP includes Powershell 3.0!</p>
<p>Let me restate: &#8220;<strong>THIS CTP INCLUDES POWERSHELL 3.0</strong>!&#8221;</p>
<p>What I hope to do is post more as I begin to learn about what is new, what is cool, what is fresh, etc.</p>
<p>A little story about me and Powershell 3.0 &#8230;.</p>
<p>When I found out about the Windows 8 &#8211; Developer Preview, I wasn&#8217;t excited about the new interface, the new look of familiar applications&#8230; no.  After I found out how to actually get to a command prompt, my first thing was to run Powershell and do a:</p>
<p>                        $host.version</p>
<p>To my UTTER DELIGHT, I saw the number &#8220;3&#8243; in the output.  My colleagues, of course, we interested in why I was ooo-ing and ahhh-ing.. then they saw that I was sitting at a Powershell prompt (of course) and the &#8220;geek&#8221;, &#8220;nerd&#8221;, and &#8220;dork&#8221; comments began.</p>
<p>Anyway, needless to say, I soon discovered I could install Powershell 3 on my Windows 7, SP1 laptop at home so I prompty did so upon arriving home from work.</p>
<p>Wow&#8230;that was a longer little story than I was expecting.</p>
<p>The bottom line is that I finally have it installed and have begun playing with it and I am a TOTAL GEEK.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>One of the things I was afraid of was losing my Powershell 2.0 installation, yet I had read that they could co-exist.  Well, seeing is believing, and I am a believer now.</p>
<p>Launching &#8220;powershell.exe&#8221; from a command line, by default, will open up version 3.</p>
<p>Launching &#8220;powershell.exe -version 2&#8243; from a command line will bring up version 2.</p>
<p>Yes, it really is that simple.</p>
<p>Upon a cursory glance at the cmdlets available I notice that there are many more geared toward command line management of the system and features.</p>
<p><em></p>
<p>       get-controlpanelitem</p>
<p>              show-controlpanelitem &#8220;Display&#8221;</p>
<p>              get-counter</p>
<p>	new-webbinding</p>
<p></em></p>
<p>Also there is a cmdlet that helps you explore all of the cmdlets available via a GUI:</p>
<p>	<em>show-command</em></p>
<p>I have, literally, been playing with the new powershell for about an hour, so stay tuned for more updates on this.</p>
<p>Please, everyone, go grab it, kick the tires, run it through its paces, and poke it with a stick.</p>
<p>As always, happy scripting and have a good time discovering Powershell 3.0.</p>
<p> &#8212; Mark</p>
]]></content:encoded>
			<wfw:commentRss>http://vmweaver.com/index.php/2011/09/powershell-3-0-drool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tag, You&#8217;re It!</title>
		<link>http://vmweaver.com/index.php/2011/07/tag-youre-it/</link>
		<comments>http://vmweaver.com/index.php/2011/07/tag-youre-it/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 03:29:28 +0000</pubDate>
		<dc:creator>Mark A. Weaver</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://vmweaver.com/?p=266</guid>
		<description><![CDATA[This will be part one of two posts to talk about a few little scripts I have been working on to help me search through my script repository. Using dropbox, I have created my own little script repository that is out in the &#8220;cloud&#8221;.  I didn&#8217;t know how much I would like it, but it certainly [...]]]></description>
			<content:encoded><![CDATA[<p>This will be part one of two posts to talk about a few little scripts I have been working on to help me search through my script repository.</p>
<p>Using dropbox, I have created my own little script repository that is out in the &#8220;cloud&#8221;.  I didn&#8217;t know how much I would like it, but it certainly makes it easy for me and others on my team to share the same scripts.</p>
<p>Anyway&#8230;the thought behind this part was to have an easy way to &#8220;tag&#8221; my scripts with information that would make it easier to search all of the scripts I have been working on.</p>
<p>All it is basically doing is creating some well-formed comments that I could then parse out.  As a safety precaution, this version makes a backup copy of the script before modifying it.  If you don&#8217;t want to back it up, just comment out the following line:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">	<span style="color: #008080; font-weight: bold;">Copy-Item</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$Script</span> <span style="color: #008080; font-style: italic;">-Destination</span> <span style="color: #800080;">$BackupScriptPath</span> <span style="color: #008080; font-style: italic;">-Force</span></pre></div></div>

<p>Without further ado, here is the code:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">&nbsp;
<span style="color: #008000;">##-------------------------------------------------------------------</span>
<span style="color: #008000;">## Script: Add-ScriptTags.ps1</span>
<span style="color: #008000;">## Written by: Mark A. Weaver </span>
<span style="color: #008000;">## Website: vmweaver.com</span>
<span style="color: #008000;">## </span>
<span style="color: #008000;">## Version: 1.0</span>
<span style="color: #008000;">## Creation Date: 7/2/2011</span>
<span style="color: #008000;">## Purpose: This script will be used to add the specified tags to a script file</span>
<span style="color: #008000;">##              It will prepend the tag data to the script text as commented strings.</span>
<span style="color: #008000;">## Markup Definitions:</span>
<span style="color: #008000;">##       _TAG:  - Comma-separated list of tag words</span>
<span style="color: #008000;">##	 _AUTH: - Text with Authors name</span>
<span style="color: #008000;">##       _DESC: - Text with Description  </span>
<span style="color: #008000;">##       _DATE: - DateTime text with last update</span>
<span style="color: #008000;">##       _VER:  - Version number</span>
<span style="color: #008000;">##       _MISC: - Miscellaneous information</span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##    </span>
<span style="color: #008000;">##   Input: </span>
<span style="color: #008000;">##                      -Script &quot;Path to Script you are tagging&quot;</span>
<span style="color: #008000;">##                      -Auth &quot;AUthor Name&quot;</span>
<span style="color: #008000;">##                      -Tag &quot;comma separated list of tags&quot;</span>
<span style="color: #008000;">##			-Desc &quot;Description of the script&quot;</span>
<span style="color: #008000;">##			-Date &quot;Date information&quot;</span>
<span style="color: #008000;">##			-Ver &quot;Script Version&quot;</span>
<span style="color: #008000;">##			-Misc &quot;Miscellaneous information you wish to include&quot;</span>
<span style="color: #008000;">##          </span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##  Output: </span>
<span style="color: #008000;">##	SCript is modified with the information. If this script is run multiple times, this </span>
<span style="color: #008000;">##      information will be over-written.</span>
<span style="color: #008000;">##                 </span>
<span style="color: #008000;">##                              </span>
<span style="color: #008000;">##  Assumptions: </span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##  Example:</span>
<span style="color: #008000;">##  	.\Add-ScriptTags.ps1 -Script ..\MyScript.ps1 -Auth &quot;Mark A. Weaver&quot; </span>
<span style="color: #008000;">##            -Tag &quot;Test,Foo,Blah&quot; -Desc &quot;Test Script&quot; -Ver &quot;1.2&quot;              </span>
<span style="color: #008000;">##               </span>
<span style="color: #008000;">#############################</span>
<span style="color: #008000;">## Updates:</span>
<span style="color: #008000;">##    </span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##----------------------------------------------------------------------</span>
&nbsp;
<span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Script</span><span style="color: pink;">=</span>$<span style="color: #000000;">&#40;</span><span style="color: #0000FF;">throw</span> <span style="color: #800000;">&quot;Script to tag must be specified!&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><span style="color: #800080;">$Tag</span><span style="color: pink;">,</span> <span style="color: #800080;">$Auth</span><span style="color: pink;">,</span> <span style="color: #800080;">$Desc</span><span style="color: pink;">,</span> <span style="color: #800080;">$Date</span><span style="color: pink;">,</span><span style="color: #800080;">$Ver</span><span style="color: pink;">,</span><span style="color: #800080;">$Misc</span><span style="color: #000000;">&#41;</span>
&nbsp;
<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;">$Script</span><span style="color: #000000;">&#41;</span> 
<span style="color: #000000;">&#123;</span>
  <span style="color: #800080;">$Contents</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800080;">$Script</span> 
  <span style="color: #000000;">&#91;</span><span style="color: #008080;">array</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$PostMarkup</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Contents</span>
&nbsp;
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">array</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Markup</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Null</span>
	<span style="color: #800080;">$Markup</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;################################&quot;</span>
	<span style="color: #800080;">$Markup</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;## _BEGINMARKUP&quot;</span>
	<span style="color: #800080;">$Markup</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;####&quot;</span>
	<span style="color: #800080;">$Markup</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;## _TAG:&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Tag</span>
	<span style="color: #800080;">$Markup</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;## _AUTH:&quot;</span><span style="color: pink;">+</span> <span style="color: #800080;">$Auth</span>
	<span style="color: #800080;">$Markup</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;## _DESC:&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Desc</span>
	<span style="color: #800080;">$Markup</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;## _DATE:&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Date</span>
	<span style="color: #800080;">$Markup</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;## _VER:&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Ver</span>
	<span style="color: #800080;">$Markup</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;## _MISC:&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Misc</span>
	<span style="color: #800080;">$Markup</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;####&quot;</span>
	<span style="color: #800080;">$Markup</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;## _ENDMARKUP&quot;</span>
	<span style="color: #800080;">$Markup</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;################################&quot;</span>
&nbsp;
 <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Contents</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;_BEGINMARKUP&quot;</span><span style="color: #000000;">&#41;</span> 
  <span style="color: #000000;">&#123;</span>
	  <span style="color: #800080;">$LineCount</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
	  <span style="color: #800080;">$BeginLine</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
	  <span style="color: #800080;">$EndLine</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
	  <span style="color: #0000FF;">Foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Line</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$Contents</span><span style="color: #000000;">&#41;</span>
	  <span style="color: #000000;">&#123;</span>
&nbsp;
	    <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Line</span> <span style="color: #FF0000;">-imatch</span> <span style="color: #800000;">&quot;_BEGINMARKUP&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$BeginLine</span> <span style="color: pink;">=</span> <span style="color: #800080;">$LineCount</span> <span style="color: pink;">-</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#125;</span>
		<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Line</span> <span style="color: #FF0000;">-imatch</span> <span style="color: #800000;">&quot;_ENDMARKUP&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$EndLine</span> <span style="color: pink;">=</span> <span style="color: #800080;">$LineCount</span> <span style="color: pink;">+</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#125;</span>
		 <span style="color: #800080;">$LineCount</span> <span style="color: pink;">+=</span> <span style="color: #804000;">1</span>
       <span style="color: #000000;">&#125;</span>
	  <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$BeginLine</span> <span style="color: #FF0000;">-eq</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#41;</span>
	  <span style="color: #000000;">&#123;</span>
	    <span style="color: #000000;">&#91;</span><span style="color: #008080;">array</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$PreMarkup</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Null</span>
	  <span style="color: #000000;">&#125;</span>
	  <span style="color: #0000FF;">else</span>
	  <span style="color: #000000;">&#123;</span>
&nbsp;
&nbsp;
	   <span style="color: #000000;">&#91;</span><span style="color: #008080;">array</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$PreMarkup</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Contents</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span>..<span style="color: #000000;">&#40;</span><span style="color: #800080;">$BeginLine</span> <span style="color: pink;">-</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	  <span style="color: #000000;">&#125;</span>
&nbsp;
	  <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$EndLine</span> <span style="color: #FF0000;">-eq</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Contents</span>.count <span style="color: pink;">-</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	  <span style="color: #000000;">&#123;</span>
         <span style="color: #000000;">&#91;</span><span style="color: #008080;">array</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$PostMarkup</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Null</span>
	  <span style="color: #000000;">&#125;</span>
	  <span style="color: #0000FF;">else</span>
	  <span style="color: #000000;">&#123;</span>
	     <span style="color: #000000;">&#91;</span><span style="color: #008080;">array</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$PostMarkup</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Contents</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$EndLine</span><span style="color: pink;">+</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>..<span style="color: #000000;">&#40;</span><span style="color: #800080;">$Contents</span>.count <span style="color: pink;">-</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	  <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #800080;">$MarkedUpScript</span> <span style="color: pink;">=</span> <span style="color: #800080;">$PreMarkup</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Markup</span> <span style="color: pink;">+</span> <span style="color: #800080;">$PostMarkup</span>
	<span style="color: #800080;">$ScriptObject</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Item</span> <span style="color: #800080;">$Script</span>
	<span style="color: #800080;">$BackupName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Backup_&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$ScriptObject</span>.Name
	<span style="color: #800080;">$BackupScriptPath</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ScriptObject</span>.DirectoryName <span style="color: pink;">+</span><span style="color: #800000;">&quot;\&quot;</span><span style="color: pink;">+</span> <span style="color: #800080;">$BackupName</span>
&nbsp;
	<span style="color: #008080; font-weight: bold;">Copy-Item</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$Script</span> <span style="color: #008080; font-style: italic;">-Destination</span> <span style="color: #800080;">$BackupScriptPath</span> <span style="color: #008080; font-style: italic;">-Force</span>
	<span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #008080; font-style: italic;">-FilePath</span> <span style="color: #800080;">$Script</span> <span style="color: #008080; font-style: italic;">-InputObject</span> <span style="color: #800080;">$MarkedupScript</span> <span style="color: #008080; font-style: italic;">-Force</span>
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;--- Markup written to '$($Script)' ---&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Green
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;--- (Backup: '$($BackupName)') ---&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> DarkYellow
        <span style="color: #800080;">$Markup</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ForEach-Object</span><span style="color: #000000;">&#123;</span><span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #000080;">$_</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> DarkGreen<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">else</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">Throw</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Script file &quot;</span><span style="color: #800000;">&quot;$Script&quot;</span><span style="color: #800000;">&quot; does not exist.&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Hope this makes sense for you.. and stay tuned for the next post which will be on processing these files and searching a repository for scripts.<br />
As always&#8230; Happy Scripting!<br />
&#8212; Mark</p>
]]></content:encoded>
			<wfw:commentRss>http://vmweaver.com/index.php/2011/07/tag-youre-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Give me some DATA! (with Powershell)</title>
		<link>http://vmweaver.com/index.php/2011/03/sql-data-with-powershell/</link>
		<comments>http://vmweaver.com/index.php/2011/03/sql-data-with-powershell/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 02:44:30 +0000</pubDate>
		<dc:creator>Mark A. Weaver</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://vmweaver.com/?p=252</guid>
		<description><![CDATA[Ah&#8230;wow.. has it really been over a YEAR since I last post? Sorry about that, but it has been an absolutely nutty year. Anyway.. In my new job and new role, I get to have fun showing people the power of automation with Powershell. One of the recent tasks I was helping with is to [...]]]></description>
			<content:encoded><![CDATA[<p>Ah&#8230;wow.. has it really been over a YEAR since I last post?  Sorry about that, but it has been an absolutely nutty year.</p>
<p>Anyway..<br />
In my new job and new role, I get to have fun showing people the power of automation with Powershell.<br />
One of the recent tasks I was helping with is to take a list of users (from AD) and query a database to get some info about these users.</p>
<p>While I had done some work with SQL queries with Powershell, I hadn&#8217;t ever &#8220;functionalized&#8221; it, so I decided to take this opportunity to do so.</p>
<p>While I am sure there are a bazillion examples of this out there, this is what I came up with and here is what it looks like.<br />
Sorry there aren&#8217;t many (any) in-line comments like I normally do, but if you have questions, please let me know!<br />
Thanks and hope you find this helpful.</p>
<p>As always&#8230; Happy Scripting!<br />
&#8211; Mark</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">##-------------------------------------------------------------------</span>
<span style="color: #008000;">## Script: Get-SQLData.ps1</span>
<span style="color: #008000;">## Written by: Mark A. Weaver </span>
<span style="color: #008000;">## Website: vmweaver.com</span>
<span style="color: #008000;">## </span>
<span style="color: #008000;">## Version: 1.0</span>
<span style="color: #008000;">## Creation Date: 3/16/2011</span>
<span style="color: #008000;">## Purpose: This is really a function that you pass 3 parameters to. It will connect to the </span>
<span style="color: #008000;">##          SQL Server you specify, to the Database you specify, and execute the</span>
<span style="color: #008000;">##          query you specify.</span>
<span style="color: #008000;">##          This connects with you existing credentials (integrated).</span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##    </span>
<span style="color: #008000;">##   Input: </span>
<span style="color: #008000;">##                      -SQLServer &quot;Name of your sql server&quot;</span>
<span style="color: #008000;">##                      -Database &quot;Name of your database&quot;</span>
<span style="color: #008000;">##                      -Query &quot;your query&quot;</span>
<span style="color: #008000;">##     *Note if you want to have a query that spans multiple lines, etc, you can pass in a </span>
<span style="color: #008000;">##      'here-string' or construct another multi-line (not array) string.</span>
<span style="color: #008000;">##          </span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##  Output: </span>
<span style="color: #008000;">##      An array is passed back containing the data from your query.</span>
<span style="color: #008000;">##      If no data is returned, the array will be $null</span>
<span style="color: #008000;">##                 </span>
<span style="color: #008000;">##                              </span>
<span style="color: #008000;">##  Assumptions: </span>
<span style="color: #008000;">##               </span>
<span style="color: #008000;">##               </span>
<span style="color: #008000;">#############################</span>
<span style="color: #008000;">## Updates:</span>
<span style="color: #008000;">##    </span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##----------------------------------------------------------------------</span>
<span style="color: #0000FF;">Function</span> Get<span style="color: pink;">-</span>SQLData
<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;">$SQLServer</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;">$Database</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;">$Query</span><span style="color: #000000;">&#41;</span>    
&nbsp;
        <span style="color: #800080;">$SQLData</span><span style="color: pink;">=@</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>     
        <span style="color: #800080;">$SqlConnection</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Data.SqlClient.SqlConnection
        <span style="color: #800080;">$SqlConnection</span>.ConnectionString <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Server = $SqlServer; Database = $Database; Integrated Security = True&quot;</span>
        <span style="color: #800080;">$SqlCmd</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Data.SqlClient.SqlCommand
        <span style="color: #800080;">$SqlCmd</span>.CommandText <span style="color: pink;">=</span> <span style="color: #800080;">$Query</span>
        <span style="color: #800080;">$SqlCmd</span>.Connection <span style="color: pink;">=</span> <span style="color: #800080;">$SqlConnection</span>
        <span style="color: #800080;">$SqlAdapter</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Data.SqlClient.SqlDataAdapter
        <span style="color: #800080;">$SqlAdapter</span>.SelectCommand <span style="color: pink;">=</span> <span style="color: #800080;">$SqlCmd</span>
        <span style="color: #800080;">$DataSet</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Data.DataSet
        <span style="color: #800080;">$SqlAdapter</span>.Fill<span style="color: #000000;">&#40;</span><span style="color: #800080;">$DataSet</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>
        <span style="color: #800080;">$SqlConnection</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #800080;">$RecordCount</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$DataSet</span>.tables<span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Measure-Object</span><span style="color: #000000;">&#41;</span>.count
        <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$RecordCount</span> <span style="color: #FF0000;">-eq</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #800080;">$SQLData</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Null</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0000FF;">else</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #800080;">$SQLData</span> <span style="color: pink;">=</span> <span style="color: #800080;">$DataSet</span>.tables<span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span> 
        <span style="color: #000000;">&#125;</span>
  <span style="color: #0000FF;">return</span> <span style="color: #800080;">$SQLData</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://vmweaver.com/index.php/2011/03/sql-data-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell and AD Object Recovery (Prologue)</title>
		<link>http://vmweaver.com/index.php/2010/02/powershell-ad-recovery-prologue/</link>
		<comments>http://vmweaver.com/index.php/2010/02/powershell-ad-recovery-prologue/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 02:11:46 +0000</pubDate>
		<dc:creator>Mark A. Weaver</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[AD]]></category>
		<category><![CDATA[Recovery]]></category>

		<guid isPermaLink="false">http://vmweaver.com/?p=229</guid>
		<description><![CDATA[I have been toying with an idea for a while since I have been diving deeper into Active Directory stuff with Powershell. The idea is to develop a full Active Directory object backup and recovery tool. There are several excellent tools available commercially that do this, but with IT staffs and budgets shrinking it is [...]]]></description>
			<content:encoded><![CDATA[<p>I have been toying with an idea for a while since I have been diving deeper into Active Directory stuff with Powershell.</p>
<p>The idea is to develop a full Active Directory object backup and recovery tool.  There are several excellent tools available commercially that do this, but with IT staffs and budgets shrinking it is often difficult to justify the cost.  </p>
<p>I am sure others have thought about it, maybe dabbled with it, but it seems to me that all of tools and components are available to do this, just that nobody (that I know of) has kind of glued them all together in an easy-to-use interface.</p>
<p>I know many of you may say &#8220;Hey, doesn&#8217;t Microsoft have an AD Recycle Bin now?&#8221;.  Well yes, they do&#8230;BUT many folks, I believe, are probably still running 2003 AD instances.  Regardless of all of that, though, this sounds like a good exercise to at least explore doing a larger-scale &#8220;application&#8221; using Powershell.</p>
<p>This will also be my first major dive in the Powershell V2.0, so I hope to be discovering new and interesting ways to put these tools together.</p>
<p>From my perspective, I see several main components that will need development:<br />
1. A user Interface.  While I have done some of this with &#8220;visual&#8221; languages and a touch with Powershell, I haven&#8217;t done anything very extensive.<br />
2. Interfacing with some type of database solution (probably SQL Server)<br />
3. Access to AD objects without 3rd party utilities. I think this will be fairly straightforward but  may end up using the Quest tools.<br />
4. Access to the &#8220;delete objects&#8221; container in the directory and a means to reanimate those objects.  (<a href="http://www.sdmsoftware.com/freeware.php">SDM Software Grou</a>p has some great cmdlets for doing this which I will probably look at using).<br />
5. General functions for manipulating AD objects (again&#8230;pretty easy)</p>
<p>One question keeps coming to mind, though is whether something like this would be useful?  I am not entirely sure, but I hope so!  To that end, I think the journey may be more worthwhile than the outcome.</p>
<p>Anyway, I hope to be spending more time with (when I *HAVE* spare time) and I hope to chronicle this &#8220;journey&#8221; here as I go.</p>
<p>If anyone has an opinion on this undertaking or has advice, please let me know.</p>
<p>Stay tuned for updates.  Right now I am standing up a small infrastructure at home to support this development effort.</p>
<p>Thanks and Happy Scripting!</p>
<p> &#8212; Mark</p>
]]></content:encoded>
			<wfw:commentRss>http://vmweaver.com/index.php/2010/02/powershell-ad-recovery-prologue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell and FSMO Roles</title>
		<link>http://vmweaver.com/index.php/2009/11/powershell-and-fsmo-roles/</link>
		<comments>http://vmweaver.com/index.php/2009/11/powershell-and-fsmo-roles/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 16:37:38 +0000</pubDate>
		<dc:creator>Mark A. Weaver</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[AD]]></category>
		<category><![CDATA[Domain]]></category>
		<category><![CDATA[FSMO]]></category>

		<guid isPermaLink="false">http://vmweaver.com/?p=218</guid>
		<description><![CDATA[Okay, this will be a quick and dirty post due to lack of time right now. This one is kind of a tip, rather than a full-blown script or topic. Basically I was looking to grab which system was the PDC Emulator for my current domain (or NOT my current domain) and so I did [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, this will be a quick and dirty post due to lack of time right now.<br />
This one is kind of a tip, rather than a full-blown script or topic.  Basically I was looking to grab which system was the PDC Emulator for my current domain (or NOT my current domain) and so I did some google-ing and finally ended up with these little functions.   </p>
<p>All I need to do is pass in the DomainName and it spits out the info.  For the FSMO roles, it will return an object and for the DomainMode, just the text is returned.</p>
<p>Hopefully you will find them useful.<br />
That&#8217;s it for now&#8230;<br />
Happy Scripting..<br />
 &#8211; Mark</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">Function</span> get<span style="color: pink;">-</span>PDCERole <span style="color: #000000;">&#40;</span><span style="color: #800080;">$DomainName</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
   <span style="color: #008000;">## Return the PDC Emulator Role Owner for the specified Domain</span>
   <span style="color: #800080;">$DomainContext</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.DirectoryServices.ActiveDirectory.DirectoryContext<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Domain&quot;</span><span style="color: pink;">,</span> <span style="color: #800080;">$DomainName</span><span style="color: #000000;">&#41;</span>
   <span style="color: #800080;">$Domain</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.DirectoryServices.ActiveDirectory.Domain<span style="color: #000000;">&#93;</span>::GetDomain<span style="color: #000000;">&#40;</span><span style="color: #800080;">$DomainContext</span><span style="color: #000000;">&#41;</span>
   <span style="color: #800080;">$PDCE</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Domain</span>.PDCRoleOwner
&nbsp;
   <span style="color: #0000FF;">Return</span> <span style="color: #800080;">$PDCE</span>  
  <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">Function</span> get<span style="color: pink;">-</span>RIDMasterRole <span style="color: #000000;">&#40;</span><span style="color: #800080;">$DomainName</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
   <span style="color: #008000;">## Return the RID Master Role Owner for the specified Domain</span>
   <span style="color: #800080;">$DomainContext</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.DirectoryServices.ActiveDirectory.DirectoryContext<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Domain&quot;</span><span style="color: pink;">,</span> <span style="color: #800080;">$DomainName</span><span style="color: #000000;">&#41;</span>
   <span style="color: #800080;">$Domain</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.DirectoryServices.ActiveDirectory.Domain<span style="color: #000000;">&#93;</span>::GetDomain<span style="color: #000000;">&#40;</span><span style="color: #800080;">$DomainContext</span><span style="color: #000000;">&#41;</span>
   <span style="color: #800080;">$RIDMaster</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Domain</span>.RIDRoleOwner
&nbsp;
   <span style="color: #0000FF;">Return</span> <span style="color: #800080;">$RIDMaster</span>
  <span style="color: #000000;">&#125;</span> 
&nbsp;
<span style="color: #0000FF;">Function</span> Get<span style="color: pink;">-</span>InfMasterRole <span style="color: #000000;">&#40;</span><span style="color: #800080;">$DomainName</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
   <span style="color: #008000;">## Return the Infrastucture Master role owner for the specified Domain</span>
   <span style="color: #800080;">$DomainContext</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.DirectoryServices.ActiveDirectory.DirectoryContext<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Domain&quot;</span><span style="color: pink;">,</span> <span style="color: #800080;">$DomainName</span><span style="color: #000000;">&#41;</span>
   <span style="color: #800080;">$Domain</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.DirectoryServices.ActiveDirectory.Domain<span style="color: #000000;">&#93;</span>::GetDomain<span style="color: #000000;">&#40;</span><span style="color: #800080;">$DomainContext</span><span style="color: #000000;">&#41;</span>
   <span style="color: #800080;">$InfMaster</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Domain</span>.InfrastructureRoleOwner
&nbsp;
   <span style="color: #0000FF;">Return</span> <span style="color: #800080;">$InfMaster</span>
 <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">Function</span> Get<span style="color: pink;">-</span>DomainMode <span style="color: #000000;">&#40;</span><span style="color: #800080;">$DomainName</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
   <span style="color: #008000;">## Return the Domain Mode for the specified Domain</span>
   <span style="color: #800080;">$DomainContext</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.DirectoryServices.ActiveDirectory.DirectoryContext<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Domain&quot;</span><span style="color: pink;">,</span> <span style="color: #800080;">$DomainName</span><span style="color: #000000;">&#41;</span>
   <span style="color: #800080;">$Domain</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.DirectoryServices.ActiveDirectory.Domain<span style="color: #000000;">&#93;</span>::GetDomain<span style="color: #000000;">&#40;</span><span style="color: #800080;">$DomainContext</span><span style="color: #000000;">&#41;</span>
   <span style="color: #800080;">$DomainMode</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Domain</span>.DomainMode
&nbsp;
   <span style="color: #0000FF;">Return</span> <span style="color: #800080;">$DomainMode</span>
&nbsp;
  <span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://vmweaver.com/index.php/2009/11/powershell-and-fsmo-roles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell and Unknown User SIDs</title>
		<link>http://vmweaver.com/index.php/2009/10/powershell-and-unknown-user-sids/</link>
		<comments>http://vmweaver.com/index.php/2009/10/powershell-and-unknown-user-sids/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 18:01:19 +0000</pubDate>
		<dc:creator>Mark A. Weaver</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[AD]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[User Management]]></category>

		<guid isPermaLink="false">http://vmweaver.com/?p=204</guid>
		<description><![CDATA[Once again, my apologies for my lack of posting.. Anyway&#8230; An interesting thing came up at work the other day when one of my fellow administrators asked me if I could resolve an unknown SID he was seeing in some logs to see what the heck it belonged to. Since I had been telling him [...]]]></description>
			<content:encoded><![CDATA[<p>Once again, my apologies for my lack of posting..</p>
<p>Anyway&#8230;</p>
<p>An interesting thing came up at work the other day when one of my fellow administrators asked me if I could resolve an unknown SID he was seeing in some logs to see what the heck it belonged to.</p>
<p>Since I had been telling him that Powershell could do ANYTHING (slight exaggeration, I know)&#8230; that it should be able to do this.</p>
<p>Well, it certainly is an interesting notion.</p>
<p>I know that I have run into this in the past where you have file system ACLs set and there are a bunch of SIDs sitting in there that nobody seems to know who they belong to.</p>
<p>While it isn&#8217;t THAT important to resolve them since the user account is most likely no longer around, it IS an interesting thought exercise.</p>
<p>After perusing the web looking for others who have done something similar, I feel I had enough to throw something together..</p>
<p>Basically when an Active Directory object (like a user) is &#8220;deleted&#8221;, it is really just Tombstoned for a period of time and is moved to the hidden container &#8220;Deleted Objects&#8221; and then removed after like 90 days or so.</p>
<p>Here is my solution to &#8220;finding&#8221; those objects.</p>
<p>First you will have to know what Domain you want to look at for this object AND you have know the SID you are looking for.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> Resolve<span style="color: pink;">-</span>DeletedUserSID<span style="color: #000000;">&#40;</span><span style="color: #800080;">$Domain</span><span style="color: pink;">,</span> <span style="color: #800080;">$UserSID</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008000;">## This is kind of a mashup of a few different scripts I found online in some forums.</span>
	<span style="color: #008000;">## Unfortunately I don't remember who did them.  If it was you, point me to your post and I will</span>
	<span style="color: #008000;">## give you the credit for your piece.</span>
	<span style="color: #008000;">## </span>
	<span style="color: #008000;">## Returns User information for deleted account with the specified SID and User Domain</span>
&nbsp;
	<span style="color: #800080;">$DomainRoot</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;LDAP://&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Domain</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$DomainDN</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>adsi<span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#40;</span> <span style="color: #800080;">$DomainRoot</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.DistinguishedName
	<span style="color: #800080;">$adspath</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;LDAP://&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$DomainDN</span>
	<span style="color: #800080;">$root</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>system.directoryservices.Directoryentry<span style="color: #000000;">&#93;</span> <span style="color: #800080;">$Adspath</span>
	<span style="color: #800080;">$root</span>.psbase.AuthenticationType <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>system.directoryservices.authenticationtypes<span style="color: #000000;">&#93;</span>::Fastbind
	<span style="color: #008000;">## We will be looking in the &quot;Deleted Objects&quot; container which is normally hidden, etc.</span>
	<span style="color: #008000;">## You will need to execute this with an account that has DomainAdmin rights to the domain you are</span>
	<span style="color: #008000;">## querying.</span>
	<span style="color: #800080;">$root</span>.psbase.path <span style="color: pink;">=</span> <span style="color: #800000;">&quot;LDAP://cn=Deleted Objects,&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$DomainDN</span>
	<span style="color: #800080;">$search</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>system.directoryservices.directorysearcher<span style="color: #000000;">&#93;</span> <span style="color: #800080;">$root</span>
	<span style="color: #800080;">$search</span>.<span style="color: #0000FF;">filter</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;(&amp;(isDeleted=TRUE)(!(objectClass=computer))(objectclass=user))&quot;</span>
	<span style="color: #800080;">$search</span>.Tombstone <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>
&nbsp;
	<span style="color: #008000;"># If you have more than 1000 users, you must NOT define SizeLimit (we haven't)</span>
	<span style="color: #008000;"># and PageSize must be less than the default value (of 1000). </span>
	<span style="color: #008000;"># I found this a bit strange...but as long as we understand it, I guess it is okay</span>
	<span style="color: #800080;">$Search</span>.PageSize <span style="color: pink;">=</span> <span style="color: #804000;">500</span>
&nbsp;
	<span style="color: #008000;"># Only look in the top level of the Deleted Objects container.</span>
	<span style="color: #800080;">$search</span>.SearchScope <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>system.directoryservices.searchscope<span style="color: #000000;">&#93;</span>::OneLevel
	<span style="color: #800080;">$result</span> <span style="color: pink;">=</span> <span style="color: #800080;">$search</span>.FindAll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># If the SID isn't found, you will get nothing returned.</span>
	<span style="color: #800080;">$result</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span> Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Name&quot;</span> ; Expression <span style="color: pink;">=</span> <span style="color: #000000;">&#123;</span> <span style="color: #000080;">$_</span>.Properties.Item<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Name&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span><span style="color: pink;">,</span> `
	<span style="color: pink;">@</span><span style="color: #000000;">&#123;</span> Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;SAMAccountName&quot;</span> ; Expression <span style="color: pink;">=</span> <span style="color: #000000;">&#123;</span> <span style="color: #000080;">$_</span>.Properties.Item<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;SAMAccountName&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span><span style="color: pink;">,</span> `
	<span style="color: pink;">@</span><span style="color: #000000;">&#123;</span> Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;SID&quot;</span> ; Expression <span style="color: pink;">=</span> <span style="color: #000000;">&#123;</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Security.Principal.SecurityIdentifier<span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.Properties.Item<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;ObjectSID&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span><span style="color: pink;">,</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span><span style="color: pink;">,</span> `
	<span style="color: pink;">@</span><span style="color: #000000;">&#123;</span> Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;WhenChanged&quot;</span> ; Expression <span style="color: pink;">=</span> <span style="color: #000000;">&#123;</span> <span style="color: #000080;">$_</span>.Properties.Item<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;WhenChanged&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> `
	<span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">where-Object</span> <span style="color: #000000;">&#123;</span> <span style="color: #000080;">$_</span>.SID <span style="color: #FF0000;">-ieq</span> <span style="color: #800080;">$UserSid</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>As always&#8230;</p>
<p>Happy Scripting!!!! and let me know if you have questions or problems.</p>
<p>&#8211; Mark</p>
]]></content:encoded>
			<wfw:commentRss>http://vmweaver.com/index.php/2009/10/powershell-and-unknown-user-sids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell &#8211; Recursive Group Membership</title>
		<link>http://vmweaver.com/index.php/2009/08/powershell-recursive-group-membership/</link>
		<comments>http://vmweaver.com/index.php/2009/08/powershell-recursive-group-membership/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 02:11:57 +0000</pubDate>
		<dc:creator>Mark A. Weaver</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Group Membership]]></category>

		<guid isPermaLink="false">http://vmweaver.com/?p=146</guid>
		<description><![CDATA[Well, I am back for yet another Powershell script. This is one that I found pretty useful actually. As one of the people really pushing automation in my group at work, I was tasked with getting a list of all users in the &#8220;Domain Admins&#8221; group for all domains in our Active Directory forest. One [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I am back for yet another Powershell script. This is one that I found pretty useful actually.<br />
As one of the people really pushing automation in my group at work, I was tasked with getting a list of all users in the &#8220;Domain Admins&#8221; group for all domains in our Active Directory forest.</p>
<p>One of the challenges in doing this is that you may have a bunch of nested groups and we needed to dump users from all nested groups, etc.  I do realize that there are probably tools and what-not that would this for me, but what fun is that and why spend the bucks if you can script it out.  I like this approach, too, because I can force the output to be whatever I want and in whichever format is best for what I am trying to accomplish.</p>
<p>From my days in college as a computer science kinda guy, I figured we could use recursion to help walk us through all nested groups.</p>
<p>So for those of you unfamilar with this idea of recursion, I will summarize:<br />
It is basically a function that calls itself until a certain condition is met. At this point the function exits. I know all you CS types may take exception to such a simplified definition, so please google for it or hit up Wikipedia for more detailed info on recursion.</p>
<p>How can this possible help us in our quest to enumeration group memberships?  Well let&#8217;s break it down a little.</p>
<ol>
<li>I start with a group I care about. Let&#8217;s say it is &#8220;Domain Admins&#8221; for domain &#8220;office1.contoso.com&#8221;.</li>
<li>I have a function (&#8220;get-groupmembers&#8221;) that I use to enumerate the members of this group and do something with them (output, write to file, etc)</li>
<li>As I am enumerating them, I find a member that is of type &#8220;group&#8221; called something like &#8220;Corp Admins&#8221;</li>
<li>I now call my function (&#8220;get-groupmembers&#8221;) with this nested group (&#8220;Corp Admins&#8221;) to enumerate the members</li>
<li>As I am enumerating them, I find ANOTHER group called &#8220;Help Desk On-Call&#8221; inside of &#8220;Corp Admins&#8221;</li>
<li>I can now call my funciton (&#8220;get-groupmembers&#8221;) ANOTHER time and keep going until I only have users and have walked all of the nested groups</li>
</ol>
<p>I know this may sound a little weird &#8220;that I am calling myself&#8221; over and over again, but it is actually pretty efficient.</p>
<p>Let&#8217;s jump into some code now.</p>
<p>For starters, I need to have some functions that take a Fully Qualified Domain Name (for an Active Directory Domain) and convert it into an LDAP-ish format.  For example, I needed &#8220;office1.contoso.com&#8221; to be transformed into &#8220;DC=office1,DC=contoso,DC=com&#8221;.  I know this isn&#8217;t rocket-surgery, but I just threw some stuff together for it.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> Convert<span style="color: pink;">-</span>DNStoDN <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;">$DNSName</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #008000;">#  Create an array of each item in the string separated by &quot;.&quot;</span>
   <span style="color: #800080;">$DNSArray</span> <span style="color: pink;">=</span> <span style="color: #800080;">$DNSName</span>.Split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #008000;"># Let's go through our new array and do something with each item</span>
   <span style="color: #0000FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$x</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>; <span style="color: #800080;">$x</span> <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$DNSArray</span>.Length ; <span style="color: #800080;">$x</span><span style="color: pink;">++</span><span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        <span style="color: #008000;">#I don't want a comma after my last item, so check to see if I am on my last one and set</span>
        <span style="color: #008000;"># $Separator equal to nothing.</span>
        <span style="color: #008000;"># Remember that we need to go to Length-1 because arrays are &quot;0 based indexes&quot;</span>
         <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$x</span> <span style="color: #FF0000;">-eq</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$DNSArray</span>.Length <span style="color: pink;">-</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Separator</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #0000FF;">else</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Separator</span> <span style="color: pink;">=</span><span style="color: #800000;">&quot;,&quot;</span><span style="color: #000000;">&#125;</span>
         <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$DN</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;DC=&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$DNSArray</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$x</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Separator</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #0000FF;">return</span> <span style="color: #800080;">$DN</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>We will also need to be able to split the FQDN of the DOMAIN out from the DN of a group or user. So, I have something like &#8220;CN=Me,OU=User1,DC=office1,DC=contoso,DC=com&#8221; and want to get the FQDN of this domain.  For this example this would output &#8220;office1.contoso.com&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> Convert<span style="color: pink;">-</span>DNtoDNS <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;">$DN</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #800080;">$DNArray</span> <span style="color: pink;">=</span> <span style="color: #800080;">$DN</span>.Split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;,&quot;</span><span style="color: #000000;">&#41;</span>
     <span style="color: #008000;"># Let's go through our new array and do something with each item</span>
   <span style="color: #0000FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$x</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>; <span style="color: #800080;">$x</span> <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$DNArray</span>.Length ; <span style="color: #800080;">$x</span><span style="color: pink;">++</span><span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        <span style="color: #008000;">#I don't want a period after my last item, so check to see if I am on my last one and set</span>
        <span style="color: #008000;"># $Separator equal to nothing.</span>
        <span style="color: #008000;"># Remember that we need to go to Length-1 because arrays are &quot;0 based indexes&quot;</span>
         <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$x</span> <span style="color: #FF0000;">-eq</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$DNArray</span>.Length <span style="color: pink;">-</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Separator</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #0000FF;">else</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$Separator</span> <span style="color: pink;">=</span><span style="color: #800000;">&quot;.&quot;</span><span style="color: #000000;">&#125;</span>
        <span style="color: #008000;"># Now we have to see if we look like &quot;DC=&quot;. If it does, we will</span>
        <span style="color: #008000;"># start to construct our DNS name.</span>
        <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$DNArray</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$x</span><span style="color: #000000;">&#93;</span>.Split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;=&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #FF0000;">-ilike</span> <span style="color: #800000;">&quot;DC&quot;</span><span style="color: #000000;">&#41;</span>
          <span style="color: #000000;">&#123;</span>
               <span style="color: #008000;"># Let's grab the &quot;contoso&quot; side of the &quot;DC=contoso&quot;</span>
              <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$DNS</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$DNArray</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$x</span><span style="color: #000000;">&#93;</span>.Split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;=&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Separator</span>
           <span style="color: #000000;">&#125;</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #0000FF;">return</span> <span style="color: #800080;">$DNS</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Now that we have those little &#8220;cameo&#8221; functions, we will move on to the more of the meat-and-potatoes of the script.<br />
The next function will be to actually enumerate a group in Active Directory without using the Quest Tools for Active Directory (if you don&#8217;t have those yet, you need to them).</p>
<p>We are actually going to use some .NET calls to get the directory objects.  My colleague <a title="Mike Hays' Blog" href="http://blog.mike-hays.net/" target="_blank">Mike Hays</a> actually did a lot of this part of the code.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> get<span style="color: pink;">-</span>groupmember<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;">$domain</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;">$groupName</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #008000;"># I have passed in the FQDN and Groupname I am interested in</span>
   <span style="color: #008000;"># I just need to convert my FQDN into an LDAP style name using my previous function</span>
   <span style="color: #800080;">$DN</span> <span style="color: pink;">=</span> convert<span style="color: pink;">-</span>DNStoDN<span style="color: #000000;">&#40;</span><span style="color: #800080;">$Domain</span><span style="color: #000000;">&#41;</span>
   <span style="color: #800080;">$domainLDAPUrl</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;LDAP://&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$DN</span>
   <span style="color: #008000;"># Setup my directory connection using .NET call</span>
   <span style="color: #800080;">$ent</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.DirectoryServices.DirectoryEntry<span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#40;</span> <span style="color: #800080;">$domainLDAPUrl</span> <span style="color: #000000;">&#41;</span>
&nbsp;
   <span style="color: #008000;"># Define my &quot;searcher&quot; object to query the directory</span>
   <span style="color: #800080;">$srch</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.DirectoryServices.DirectorySearcher<span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#40;</span> <span style="color: #800080;">$ent</span> <span style="color: #000000;">&#41;</span>
&nbsp;
   <span style="color: #008000;"># Setup my search criteria.. looking for all Groups with CN=GroupName</span>
   <span style="color: #800080;">$groupNameFilter</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;(&amp;(objectClass=group)(CN=&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$groupName</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;))&quot;</span>
   <span style="color: #800080;">$srch</span>.<span style="color: #0000FF;">Filter</span> <span style="color: pink;">=</span> <span style="color: #800080;">$groupNameFilter</span>
&nbsp;
   <span style="color: #008000;"># Now go execute my query to and put the results in $coll</span>
   <span style="color: #800080;">$coll</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.DirectoryServices.SearchResultCollection<span style="color: #000000;">&#93;</span>      <span style="color: #800080;">$srch</span>.FindAll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
   <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$rs</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$coll</span><span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
       <span style="color: #008000;"># Now get a collection of properties for that object</span>
       <span style="color: #800080;">$resultPropColl</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.DirectoryServices.ResultPropertyCollection<span style="color: #000000;">&#93;</span> <span style="color: #800080;">$rs</span>.Properties
&nbsp;
       <span style="color: #008000;"># Cycle through all group members</span>
       <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$memberColl</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$resultPropColl</span><span style="color: #000000;">&#91;</span><span style="color: #800000;">&quot;member&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
         <span style="color: #000000;">&#123;</span>
           <span style="color: #008000;"># Build my membership array</span>
           <span style="color: #000000;">&#91;</span><span style="color: #008080;">array</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$gpMemberEntry</span> <span style="color: pink;">+=</span> <span style="color: #000000;">&#91;</span>System.DirectoryServices.DirectoryEntry<span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#40;</span> <span style="color: #800000;">&quot;LDAP://&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$memberColl</span> <span style="color: #000000;">&#41;</span>
          <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
  <span style="color: #008000;"># Send back my group members.</span>
  <span style="color: #0000FF;">return</span> <span style="color: #800080;">$gpMemberEntry</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Okay.. now that we have THAT setup let&#8217;s talk about the next bits of code.<br />
This is where we will have our recursive function &#8220;Get-AllMembers&#8221;.  In it, you will a call to itself.  One of the biggest concerns is that you can end up in an unending or infinite cycle.  I don&#8217;t really do any checking in this little scripty-do-dad, so that may be something for later.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> get<span style="color: pink;">-</span>allmembers<span style="color: #000000;">&#40;</span><span style="color: #800080;">$objectName</span><span style="color: pink;">,</span> <span style="color: #800080;">$OF</span><span style="color: pink;">,</span> <span style="color: #800080;">$GN</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #008000;"># Split out my domain name  (should be FQDN) and the group name</span>
    <span style="color: #800080;">$domainName</span> <span style="color: pink;">=</span> <span style="color: #800080;">$objectname</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;\&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>
    <span style="color: #800080;">$ObjectName</span> <span style="color: pink;">=</span> <span style="color: #800080;">$objectname</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;\&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>
&nbsp;
    <span style="color: #800080;">$members</span> <span style="color: pink;">=</span> get<span style="color: pink;">-</span>groupmember <span style="color: #800000;">&quot;$DomainName&quot;</span> <span style="color: #800000;">&quot;$ObjectName&quot;</span>
    <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$members</span> <span style="color: #FF0000;">-ne</span> <span style="color: #800080;">$NULL</span><span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
        <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$member</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$members</span><span style="color: #000000;">&#41;</span>
         <span style="color: #000000;">&#123;</span>
            <span style="color: #008000;">#  Grab the domain DNS name out of the object DN</span>
            <span style="color: #800080;">$ObjDomain</span> <span style="color: pink;">=</span> convert<span style="color: pink;">-</span>DNtoDNS <span style="color: #800080;">$Member</span>.DistinguishedName
            <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$member</span>.objectclass <span style="color: #FF0000;">-contains</span> <span style="color: #800000;">&quot;group&quot;</span><span style="color: #000000;">&#41;</span>
              <span style="color: #000000;">&#123;</span>
                 <span style="color: #008000;">#If my group member is, itself, a group We get to do some recursion</span>
                  <span style="color: #800080;">$out</span> <span style="color: pink;">=</span> <span style="color: #800080;">$objDomain</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;\&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$member</span>.name
                  <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$out</span>
                  <span style="color: #008000;"># Call myself with the nested group name</span>
                  get<span style="color: pink;">-</span>allmembers <span style="color: pink;">-</span>ObjectName <span style="color: #800080;">$out</span> <span style="color: pink;">-</span>OF <span style="color: #800080;">$of</span> <span style="color: pink;">-</span>GN <span style="color: #800080;">$GN</span>
               <span style="color: #000000;">&#125;</span>
            <span style="color: #0000FF;">else</span>
               <span style="color: #000000;">&#123;</span>
                  <span style="color: #008000;"># If I get back a user, then see if the user is disabled or not</span>
                  <span style="color: #800080;">$userAndDomain</span> <span style="color: pink;">=</span> <span style="color: #800080;">$objDomain</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;\&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$member</span>.name
                  <span style="color: #008000;"># The  UserAccountControl property contains several &quot;flags&quot;</span>
                  <span style="color: #008000;"># that we can interrogate.  By doing a Binary AND we are seeing if the 2nd flag is set.</span>
                  <span style="color: #000000;">&#91;</span><span style="color: #008080;">bool</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$accountIsDisabled</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$member</span>.userAccountControl.ToSTring<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-band</span> <span style="color: #804000;">2</span>
&nbsp;
                  <span style="color: #008000;"># Setup our output (I am choosing to construct a comma-delimited type of output</span>
                  <span style="color: #800080;">$OutText</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;'&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$GN</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;','&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$objDomain</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;','&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Member</span>.Samaccountname <span style="color: pink;">+</span> <span style="color: #800000;">&quot;','&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Member</span>.displayName <span style="color: pink;">+</span> <span style="color: #800000;">&quot;','&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$member</span>.distinguishedName <span style="color: pink;">+</span> <span style="color: #800000;">&quot;','&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$objectname</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;','&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$accountIsDisabled</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;'&quot;</span>
&nbsp;
                  <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #008080; font-style: italic;">-FilePath</span> <span style="color: #800080;">$OF</span> <span style="color: #008080; font-style: italic;">-inputobject</span> <span style="color: #800080;">$Outtext</span> <span style="color: #008080; font-style: italic;">-append</span> <span style="color: #008080; font-style: italic;">-Encoding</span> <span style="color: #800000;">&quot;ASCII&quot;</span>
&nbsp;
                  <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$OutText</span>
                <span style="color: #000000;">&#125;</span>
         <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0000FF;">else</span>
     <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;No Members or no Group:&quot;</span> <span style="color: #800080;">$ObjectName</span> <span style="color: #800000;">&quot;in Domain:&quot;</span> <span style="color: #800080;">$DomainName</span> <span style="color: pink;">-</span>Foreground RED
     <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;">###########################</span>
<span style="color: #008000;">## Main</span>
<span style="color: #008000;">###########################</span>
<span style="color: #800080;">$GroupName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Domain Admins&quot;</span>
<span style="color: #800080;">$Today</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Date</span> <span style="color: #008080; font-style: italic;">-format</span> <span style="color: #800000;">&quot;yyyyMMddhh&quot;</span>
<span style="color: #800080;">$OutputFolder</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;C:\Temp\&quot;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Test-Path</span> <span style="color: #800080;">$outputFolder</span><span style="color: #000000;">&#41;</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: #008080; font-weight: bold;">New-Item</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$OutputFolder</span> <span style="color: pink;">-</span><span style="color: #008080; font-weight: bold;">Type</span> Directory <span style="color: pink;">&gt;</span> <span style="color: #800080;">$NULL</span>
  <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Grab my forest info</span>
<span style="color: #800080;">$forest</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.DirectoryServices.ActiveDirectory.Forest<span style="color: #000000;">&#93;</span>::GetCurrentForest<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;">#Setup my output file</span>
<span style="color: #800080;">$OutHeader</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;'Group','UserDomain','SAMAccount','DisplayName','DN','MemberofGroup','IsDisabled'&quot;</span>
&nbsp;
<span style="color: #008000;"># Define output file name</span>
<span style="color: #800080;">$of</span> <span style="color: pink;">=</span> <span style="color: #800080;">$OutputFolder</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Today</span> <span style="color: pink;">+</span><span style="color: #800000;">&quot;_&quot;</span><span style="color: pink;">+</span> <span style="color: #800080;">$GroupName</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;-AuditReport.txt&quot;</span>
&nbsp;
<span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #008080; font-style: italic;">-FilePath</span> <span style="color: #800080;">$OF</span> <span style="color: #008080; font-style: italic;">-inputobject</span> <span style="color: #800080;">$OutHeader</span> <span style="color: #008080; font-style: italic;">-Encoding</span> <span style="color: #800000;">&quot;ASCII&quot;</span>
&nbsp;
<span style="color: #008000;"># Cycle through all the child domains in the forest root to query for Group.</span>
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$domain</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$forest</span>.Domains<span style="color: #000000;">&#41;</span>
 <span style="color: #000000;">&#123;</span>
    <span style="color: #800080;">$FullGroupName</span> <span style="color: pink;">=</span> <span style="color: #800080;">$domain</span>.name <span style="color: pink;">+</span> <span style="color: #800000;">&quot;\&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$GroupName</span>
    get<span style="color: pink;">-</span>allmembers <span style="color: pink;">-</span>ObjectName <span style="color: #800080;">$FullGroupName</span> <span style="color: pink;">-</span>OF <span style="color: #800080;">$of</span> <span style="color: pink;">-</span>GN <span style="color: #800080;">$FullGroupName</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Just take all of the script blocks from above and paste them into your script.  I am trying to keep these posts a bit shorter, so you may see upcoming posts broken out into parts.</p>
<p>Well, I think I am done here with this one.  Please let me know if you have questions, concerns, or comments.</p>
<p>Please keep in mind that this script will attempt to enumerate the Group in  ALL child domains in your current AD Forest.  If you have a large Forest with lots of child domains&#8230;..this could take a while.</p>
<p>I will be happy to help out with requested changes if they seem like they would be beneficial overall, but I am also a STRONG advocate of doing-it-yourself.<br />
Every bit of Powershell and scripting I have learned by grabbing it and going with it.</p>
<p>Anyway, as always&#8230;thanks for stopping by and happy scripting!!!</p>
<p>&#8211; Mark</p>
]]></content:encoded>
			<wfw:commentRss>http://vmweaver.com/index.php/2009/08/powershell-recursive-group-membership/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Binary Search and Powershell</title>
		<link>http://vmweaver.com/index.php/2009/07/binary-search-and-powershell/</link>
		<comments>http://vmweaver.com/index.php/2009/07/binary-search-and-powershell/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 03:53:52 +0000</pubDate>
		<dc:creator>Mark A. Weaver</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Binary Search]]></category>
		<category><![CDATA[EventLog]]></category>

		<guid isPermaLink="false">http://vmweaver.com/?p=142</guid>
		<description><![CDATA[Time for another Powershell Post. So, what is a binary search and why should you care about it? Well, it provides us a mechanism to very quickly search through an ordered list of &#8220;things&#8221; (like event log entries). It is especially useful when looking through LARGE amounts of data. I know, I know.. There are [...]]]></description>
			<content:encoded><![CDATA[<p>Time for another Powershell Post.<br />
So, what is a binary search and why should you care about it?</p>
<p>Well, it provides us a mechanism to very quickly search through an ordered list of &#8220;things&#8221; (like event log entries). It is especially useful when looking through LARGE amounts of data.</p>
<p>I know, I know.. There are all sorts of ways to look through/filter/search event logs and everyone has probably written about this already, but I guess I feel compelled to put in my 2 cents.</p>
<p>We ran into the need to be able to pull event log entries from a specific period of time on several servers.<br />
There aren&#8217;t really any &#8220;native&#8221; Powershell methods to query Eventlogs from REMOTE servers (unless you are on CTP and hitting Vista/2K8 systems).</p>
<p>So a little info about a binary search:</p>
<p>Lets say we have a list of things as follows:</p>
<table border="1" cellspacing="0" cellpadding="4" width="198" bordercolor="#000000">
<colgroup span="1">
<col span="1" width="48"></col>
<col span="1" width="47"></col>
<col span="1" width="77"></col>
</colgroup>
<tbody>
<tr valign="top">
<td width="48" bgcolor="#000000">
<p align="center"><span style="color: #ffffff;"><strong>Index</strong></span></p>
</td>
<td width="47" bgcolor="#000000">
<p align="center"><span style="color: #ffffff;"><strong>Name</strong></span></p>
</td>
<td width="77" bgcolor="#000000">
<p align="center"><span style="color: #ffffff;"><strong>DOB</strong></span></p>
</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">0</p>
</td>
<td width="47">Adam</td>
<td width="77">01/20/80</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">1</p>
</td>
<td width="47">Cheryl</td>
<td width="77">09/16/77</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">2</p>
</td>
<td width="47">Frank</td>
<td width="77">04/01/82</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">3</p>
</td>
<td width="47">Ivan</td>
<td width="77">10/26/70</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">4</p>
</td>
<td width="47">Suzy</td>
<td width="77">04/10/90</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">5</p>
</td>
<td width="47">Tim</td>
<td width="77">11/21/62</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">6</p>
</td>
<td width="47">Wendy</td>
<td width="77">02/02/71</td>
</tr>
</tbody>
</table>
<p>And we are wanting to find which index “Suzy” is in the list.</p>
<p>One way would be to start at the top of the list and see if the Name matches. On a short list this may make sense since it is really only 5 compares before we find her.</p>
<p>But if I was looking for “Suzy” in a list the size of a phone book this can take a long time and a lot of horsepower to find her and may take 300,000 compares or more.</p>
<p>A binary search algorithm helps us by breaking the list down by using something we already know about the list: that it is sorted by name.</p>
<p>With a single compare, though, we can cut the list of viable options in half.</p>
<p>All we need to do is take the index of our smallest value [0] and we add it to the index of our largest element [6] and divide by 2, we get the index of our middle element [3]. Now lets compare what we are looking for (“Suzy”) to the value of element [3].</p>
<p>LowerBound Index = 0<br />
UpperBound Index = 6<br />
Mid Index = (6+0)\2 = 3</p>
<p>Lets take a look at this:</p>
<table border="1" cellspacing="0" cellpadding="4" width="198" bordercolor="#000000">
<colgroup span="1">
<col span="1" width="48"></col>
<col span="1" width="47"></col>
<col span="1" width="77"></col>
</colgroup>
<tbody>
<tr valign="top">
<td width="48" bgcolor="#000000">
<p align="center"><span style="color: #ffffff;"><strong>Index</strong></span></p>
</td>
<td width="47" bgcolor="#000000">
<p align="center"><span style="color: #ffffff;"><strong>Name</strong></span></p>
</td>
<td width="77" bgcolor="#000000">
<p align="center"><span style="color: #ffffff;"><strong>DOB</strong></span></p>
</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">0</p>
</td>
<td width="47">Adam</td>
<td width="77">01/20/80</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">1</p>
</td>
<td width="47">Cheryl</td>
<td width="77">09/16/77</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">2</p>
</td>
<td width="47">Frank</td>
<td width="77">04/01/82</td>
</tr>
<tr valign="top">
<td width="48" bgcolor="#e6e6ff">
<p align="center">3</p>
</td>
<td width="47" bgcolor="#e6e6ff">Ivan</td>
<td width="77" bgcolor="#e6e6ff">10/26/70</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">4</p>
</td>
<td width="47">Suzy</td>
<td width="77">04/10/90</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">5</p>
</td>
<td width="47">Tim</td>
<td width="77">11/21/62</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">6</p>
</td>
<td width="47">Wendy</td>
<td width="77">02/02/71</td>
</tr>
</tbody>
</table>
<p>Obviously “Suzy” is greater than our value at index [3] “Ivan”. Since we know this, we can throw out all indexes that are [3] and lower.</p>
<p>Our list of viable options now becomes this:</p>
<table border="1" cellspacing="0" cellpadding="4" width="198" bordercolor="#000000">
<colgroup span="1">
<col span="1" width="48"></col>
<col span="1" width="47"></col>
<col span="1" width="77"></col>
</colgroup>
<tbody>
<tr valign="top">
<td width="48">
<p align="center">4</p>
</td>
<td width="47">Suzy</td>
<td width="77">04/10/90</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">5</p>
</td>
<td width="47">Tim</td>
<td width="77">11/21/62</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">6</p>
</td>
<td width="47">Wendy</td>
<td width="77">02/02/71</td>
</tr>
</tbody>
</table>
<p style="MARGIN-BOTTOM: 0in">Let&#8217;s repeat this exercise on our new list:</p>
<p style="MARGIN-BOTTOM: 0in">Lowest index = 4</p>
<p style="MARGIN-BOTTOM: 0in">Largest index = 6</p>
<p style="MARGIN-BOTTOM: 0in">Middle index = (6+4) /2 = 5</p>
<p style="MARGIN-BOTTOM: 0in"> </p>
<table border="1" cellspacing="0" cellpadding="4" width="198" bordercolor="#000000">
<colgroup span="1">
<col span="1" width="48"></col>
<col span="1" width="47"></col>
<col span="1" width="77"></col>
</colgroup>
<tbody>
<tr valign="top">
<td width="48">
<p align="center">4</p>
</td>
<td width="47">Suzy</td>
<td width="77">04/10/90</td>
</tr>
<tr valign="top">
<td width="48" bgcolor="#e6e6e6">
<p align="center">5</p>
</td>
<td width="47" bgcolor="#e6e6e6">Tim</td>
<td width="77" bgcolor="#e6e6e6">11/21/62</td>
</tr>
<tr valign="top">
<td width="48">
<p align="center">6</p>
</td>
<td width="47">Wendy</td>
<td width="77">02/02/71</td>
</tr>
</tbody>
</table>
<p style="MARGIN-BOTTOM: 0in"> So now we compare what we are looking for “Suzy” to our element [5] (“Tim”). Well, “Suzy is less than “Tim”, so that means we can throw out indexes that are [5] and higher.</p>
<p style="MARGIN-BOTTOM: 0in"> </p>
<table border="1" cellspacing="0" cellpadding="4" width="198" bordercolor="#000000">
<colgroup span="1">
<col span="1" width="48"></col>
<col span="1" width="47"></col>
<col span="1" width="77"></col>
</colgroup>
<tbody>
<tr valign="top">
<td width="48" bgcolor="#e6e6e6">
<p align="center">4</p>
</td>
<td width="47" bgcolor="#e6e6e6">Suzy</td>
<td width="77" bgcolor="#e6e6e6">04/10/90</td>
</tr>
</tbody>
</table>
<p style="MARGIN-BOTTOM: 0in"> Let&#8217;s go one more time&#8230;. oh wait.. .there is only one thing left&#8230;.it&#8217;s “Suzy”. We have found her.</p>
<p style="MARGIN-BOTTOM: 0in"> </p>
<p style="MARGIN-BOTTOM: 0in">There ARE .NET methods (of [System.Array]) that enable us to do binary searches of Arrays for Strings. The only problem is that it will be looking for EXACT matches for the string.</p>
<p style="MARGIN-BOTTOM: 0in"> </p>
<p style="MARGIN-BOTTOM: 0in">This poses a problem for us if we are looking for something that is a little less exact.</p>
<p style="MARGIN-BOTTOM: 0in"> </p>
<p style="MARGIN-BOTTOM: 0in"><span style="font-size: large;"><em>Mark&#8217;s Modified Binary Search</em></span></p>
<p>Okay, leave it to me to mess with a good thing.</p>
<p>My problem is that I want to grab all events from the System event log that occurred between 8pm and 9pm last night.</p>
<p>This is a little more “fuzzy” than exact, so let me show you what I did&#8230;.heh</p>
<p> I know you all are getting a little antsy for some code, but we will get there soon.. Stay with me.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> Get<span style="color: pink;">-</span>DatedLogEntries<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;">$ServerName</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;">$EventLogName</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span>datetime<span style="color: #000000;">&#93;</span><span style="color: #800080;">$OldestTime</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span>datetime<span style="color: #000000;">&#93;</span><span style="color: #800080;">$NewestTime</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #008000;">#Grabbing my Eventlog Entries</span>
	<span style="color: #800080;">$EventLog</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Diagnostics.EventLog<span style="color: #000000;">&#40;</span><span style="color: #800080;">$EventlogName</span><span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$EventLog</span>.MachineName <span style="color: pink;">=</span> <span style="color: #800080;">$ServerName</span>
	<span style="color: #800080;">$Entries</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Eventlog</span>.Entries</pre></div></div>

<p>There are some cmdlets designed to return eventlog entries, but they are only really effective if you are querying the local server or if you are leveraging the “new” Powershell Remoting, but you have to be running against Vista or Server 2008.</p>
<p>Fortunately, there is a way to grab remote event log entries via .NET (as shown in the code above)</p>
<p>When done, $Entries will contain all of the events in the logfile sorted by Time.</p>
<p>Next, we will setup our “bound”ing values for our array of entries and the times we are looking for.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#Defining my starting boundaries of my array</span>
<span style="color: #800080;">$Ubound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Entries</span>.count <span style="color: pink;">-</span> <span style="color: #804000;">1</span>
<span style="color: #800080;">$Lbound</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
<span style="color: #800080;">$Mid</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
<span style="color: #008000;">#Setting up my dates</span>
<span style="color: #800080;">$StartTime</span> <span style="color: pink;">=</span> <span style="color: #800080;">$OldestTime</span>
<span style="color: #800080;">$EndTime</span> <span style="color: pink;">=</span> $NewestTime</pre></div></div>

<p>Now we are ready for the real work. Because I want to grab a range of events, I will run through the binary search two times. The first time will tell me what the UpperBound of my list is, and the second will tell me what the LowerBound of my list is as array indexes.</p>
<p>Before we start checking anything, we can make sure our search isn&#8217;t for naught.</p>
<p>Many systems have event logs that can roll pretty quickly, so we can just compare the oldest event to our start time. If the oldest event is newer than my start time, then my logs have rolled and I won&#8217;t have any data.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$StartTime</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Ubound</span> <span style="color: pink;">-</span> <span style="color: #800080;">$Lbound</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-gt</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #800080;">$Mid</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Ubound</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Lbound</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">/</span> <span style="color: #804000;">2</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">#Calculate my midpoint</span>
  <span style="color: #008000;">#Compare my midpoint to my StartTime</span>
  <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Mid</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$StartTime</span><span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
  <span style="color: #008000;">#If my midpoint is less than my Start time, then throw out all events</span>
  <span style="color: #008000;">#below and including my Midpoint</span>
        <span style="color: #800080;">$LBound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span> <span style="color: pink;">+</span> <span style="color: #804000;">1</span>
     <span style="color: #000000;">&#125;</span>
   <span style="color: #0000FF;">elseif</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Mid</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$StartTime</span><span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
     <span style="color: #008000;">#If my midpoint is greater than my Start time, then throw out all events</span>
      <span style="color: #008000;">#above and including my Midpoint</span>
      <span style="color: #800080;">$Ubound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span><span style="color: pink;">-</span><span style="color: #804000;">1</span>
     <span style="color: #000000;">&#125;</span>
    <span style="color: #0000FF;">else</span>
     <span style="color: #000000;">&#123;</span>
     <span style="color: #008000;">#If my midpoint is equal to my Start time, then I got lucky and found my time.</span>
     <span style="color: #008000;">#I just realized that I may need to do something else with this. May tackle that</span>
     <span style="color: #008000;"># later though...</span>
      <span style="color: #800080;">$Ubound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span>
      <span style="color: #800080;">$LBound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span>
     <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
 <span style="color: #008000;"># Now I know that the array index of our oldest item is here</span>
 <span style="color: #800080;">$Oldest</span> <span style="color: pink;">=</span> $LBound</pre></div></div>

<p>Now we will repeat the process to find out LowerBound. I won&#8217;t document it too much since it is nearly identical code to above. If you have questions, please let me know.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$Ubound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Entries</span>.count <span style="color: pink;">-</span> <span style="color: #804000;">1</span>
<span style="color: #800080;">$Lbound</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
<span style="color: #800080;">$Mid</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
<span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Ubound</span> <span style="color: pink;">-</span> <span style="color: #800080;">$Lbound</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-gt</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
   <span style="color: #800080;">$Mid</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Ubound</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Lbound</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">/</span> <span style="color: #804000;">2</span> <span style="color: #000000;">&#41;</span>
   <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Mid</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$EndTime</span><span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
      <span style="color: #800080;">$LBound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span> <span style="color: pink;">+</span> <span style="color: #804000;">1</span>
     <span style="color: #000000;">&#125;</span>
    <span style="color: #0000FF;">elseif</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Mid</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$EndTime</span><span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
      <span style="color: #800080;">$Ubound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span><span style="color: pink;">-</span><span style="color: #804000;">1</span>
     <span style="color: #000000;">&#125;</span>
    <span style="color: #0000FF;">else</span>
    <span style="color: #000000;">&#123;</span>
     <span style="color: #800080;">$Ubound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span>
     <span style="color: #800080;">$LBound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span>
    <span style="color: #000000;">&#125;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$Newest</span> <span style="color: pink;">=</span> $LBound</pre></div></div>

<p>So now we have the LowerBound index for the range I am looking for.<br />
Now to finish it up&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Sometimes we can end up with endpoints that don't meet our time range</span>
<span style="color: #008000;"># We fix that by going through each side and adjusting them until they</span>
<span style="color: #008000;"># are correct</span>
 <span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Newest</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$Endtime</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
   <span style="color: #800080;">$Newest</span><span style="color: pink;">--</span>
  <span style="color: #000000;">&#125;</span>
&nbsp;
 <span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Oldest</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$StartTime</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
   <span style="color: #800080;">$Oldest</span><span style="color: pink;">++</span>
  <span style="color: #000000;">&#125;</span>	
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Newest</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$StartTime</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Oldest</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$EndTime</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
 <span style="color: #000000;">&#123;</span>
    <span style="color: #008000;">#Insert Code here if you want to do something when</span>
    <span style="color: #008000;">#no events found during the period requested..</span>
    <span style="color: #800080;">$EntriesByDate</span> <span style="color: pink;">=</span> <span style="color: #800080;">$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 a new array and assign it the $Entries indexes ranging from our 'oldest' to our 'newest'</span>
    <span style="color: #800080;">$EntriesByDate</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Oldest</span>..<span style="color: #800080;">$Newest</span><span style="color: #000000;">&#93;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">else</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008000;">#Insert Code here if you want to do something when</span>
	<span style="color: #008000;"># Logs have rolled... and none were in the specified range.</span>
	<span style="color: #800080;">$EntriesByDate</span> <span style="color: pink;">=</span> <span style="color: #800080;">$NULL</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">return</span> <span style="color: #800080;">$EntriesByDate</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I hope I was able to articulate this effectively. As always, let me know if you have questions, comments, or suggestions.<br />
Thanks for Reading and happy shelling.<br />
So, that is basically it. Here is the code in one big block:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">## Get-DatedLogEntries Function</span>
<span style="color: #008000;">## Written by: Mark A. Weaver</span>
<span style="color: #008000;">## Website: www.vmweaver.com</span>
<span style="color: #008000;">## Version: 1.0</span>
<span style="color: #008000;">## Date: 7/23/2009</span>
<span style="color: #008000;">## Purpose: This Function will get event log entries from the specified server using currently logged in</span>
<span style="color: #008000;">##          credentials and return an array of Events that occurred between the 2 times.</span>
<span style="color: #008000;">##          Not much error checking or validation is done, so you please edit to your liking.</span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##        Input:</span>
<span style="color: #008000;">##				-ServerName &quot;ServerName&quot;</span>
<span style="color: #008000;">##				-EventLogName &quot;EventLogName&quot;</span>
<span style="color: #008000;">##          -OldestTime [DateTime]OldestTime</span>
<span style="color: #008000;">##				-NewestTime [Datetime]NewestTime</span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##        Output:</span>
<span style="color: #008000;">##				Array of Event log entries or Null if none found</span>
<span style="color: #008000;">#############################</span>
<span style="color: #008000;">## Updates:</span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">######################################################################</span>
<span style="color: #008000;">######################################################################</span>
&nbsp;
<span style="color: #0000FF;">function</span> Get<span style="color: pink;">-</span>DatedLogEntries<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;">$ServerName</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;">$EventLogName</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span>datetime<span style="color: #000000;">&#93;</span><span style="color: #800080;">$OldestTime</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span>datetime<span style="color: #000000;">&#93;</span><span style="color: #800080;">$NewestTime</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #008000;">#Grabbing my Eventlog Entries</span>
	<span style="color: #800080;">$EventLog</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Diagnostics.EventLog<span style="color: #000000;">&#40;</span><span style="color: #800080;">$EventlogName</span><span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$EventLog</span>.MachineName <span style="color: pink;">=</span> <span style="color: #800080;">$ServerName</span>
	<span style="color: #800080;">$Entries</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Eventlog</span>.Entries
&nbsp;
	<span style="color: #008000;">#Defining my starting boundaries of my array</span>
	<span style="color: #800080;">$Ubound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Entries</span>.count <span style="color: pink;">-</span> <span style="color: #804000;">1</span>
	<span style="color: #800080;">$Lbound</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
	<span style="color: #800080;">$Mid</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
	<span style="color: #008000;">#Setting up my dates</span>
	<span style="color: #800080;">$StartTime</span> <span style="color: pink;">=</span> <span style="color: #800080;">$OldestTime</span>
	<span style="color: #800080;">$EndTime</span> <span style="color: pink;">=</span> <span style="color: #800080;">$NewestTime</span> 
&nbsp;
	<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$StartTime</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Ubound</span> <span style="color: pink;">-</span> <span style="color: #800080;">$Lbound</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-gt</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #800080;">$Mid</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Ubound</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Lbound</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">/</span> <span style="color: #804000;">2</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">#Calculate my midpoint</span>
			<span style="color: #008000;">#Compare my midpoint to my StartTime</span>
			<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Mid</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$StartTime</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #008000;">#If my midpoint is less than my Start time, then throw out all events</span>
				<span style="color: #008000;">#below and including my Midpoint</span>
				<span style="color: #800080;">$LBound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span> <span style="color: pink;">+</span> <span style="color: #804000;">1</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0000FF;">elseif</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Mid</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$StartTime</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #008000;">#If my midpoint is greater than my Start time, then throw out all events</span>
				<span style="color: #008000;">#above and including my Midpoint</span>
				<span style="color: #800080;">$Ubound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span><span style="color: pink;">-</span><span style="color: #804000;">1</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0000FF;">else</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #008000;">#If my midpoint is equal to my Start time, then I got lucky and found my time.</span>
				<span style="color: #008000;">#I just realized that I may need to do something else with this. May tackle that</span>
				<span style="color: #008000;"># later though...</span>
				<span style="color: #800080;">$Ubound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span>
				<span style="color: #800080;">$LBound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #008000;"># Now I know that the array index of our oldest item is here</span>
		<span style="color: #800080;">$Oldest</span> <span style="color: pink;">=</span> <span style="color: #800080;">$LBound</span> 
&nbsp;
		<span style="color: #800080;">$Ubound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Entries</span>.count <span style="color: pink;">-</span> <span style="color: #804000;">1</span>
		<span style="color: #800080;">$Lbound</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
		<span style="color: #800080;">$Mid</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
		<span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Ubound</span> <span style="color: pink;">-</span> <span style="color: #800080;">$Lbound</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-gt</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #800080;">$Mid</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Ubound</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Lbound</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">/</span> <span style="color: #804000;">2</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Mid</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$EndTime</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #800080;">$LBound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span> <span style="color: pink;">+</span> <span style="color: #804000;">1</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0000FF;">elseif</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Mid</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$EndTime</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #800080;">$Ubound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span><span style="color: pink;">-</span><span style="color: #804000;">1</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0000FF;">else</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #800080;">$Ubound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span>
				<span style="color: #800080;">$LBound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Mid</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #800080;">$Newest</span> <span style="color: pink;">=</span> <span style="color: #800080;">$LBound</span>		
&nbsp;
		<span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Newest</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$Endtime</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #800080;">$Newest</span><span style="color: pink;">--</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Oldest</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$StartTime</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #800080;">$Oldest</span><span style="color: pink;">++</span>
		<span style="color: #000000;">&#125;</span>	
&nbsp;
		<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Newest</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$StartTime</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Oldest</span><span style="color: #000000;">&#93;</span>.TimeGenerated <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$EndTime</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008000;">#No events found during the period requested..</span>
			<span style="color: #800080;">$EntriesByDate</span> <span style="color: pink;">=</span> <span style="color: #800080;">$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 a new array and assign it the $Entries indexes ranging from our 'oldest' to our 'newest'</span>
			<span style="color: #800080;">$EntriesByDate</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Entries</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$Oldest</span>..<span style="color: #800080;">$Newest</span><span style="color: #000000;">&#93;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">else</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;"># Logs have rolled... and none were in the specified range.</span>
		<span style="color: #800080;">$EntriesByDate</span> <span style="color: pink;">=</span> <span style="color: #800080;">$NULL</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">return</span> <span style="color: #800080;">$EntriesByDate</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://vmweaver.com/index.php/2009/07/binary-search-and-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell and DFSR</title>
		<link>http://vmweaver.com/index.php/2009/04/powershell-and-dfsr/</link>
		<comments>http://vmweaver.com/index.php/2009/04/powershell-and-dfsr/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 16:22:56 +0000</pubDate>
		<dc:creator>Mark A. Weaver</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[dfs]]></category>
		<category><![CDATA[dfsr]]></category>

		<guid isPermaLink="false">http://vmweaver.com/?p=126</guid>
		<description><![CDATA[Sorry for the long delay between posts, but work has been absolutely crazy. Anyway, one of the recent tasks I have been working on is to find a way to check DFSR to make sure that our remote sites are properly replicating data back to our corporate datacenter.  Part of this new infrastructure relies heavily [...]]]></description>
			<content:encoded><![CDATA[<p>Sorry for the long delay between posts, but work has been absolutely crazy.</p>
<p>Anyway, one of the recent tasks I have been working on is to find a way to check DFSR to make sure that our remote sites are properly replicating data back to our corporate datacenter.  Part of this new infrastructure relies heavily on Microsoft DFSR and all the cool stuff it brings (in 2003 R2).</p>
<p>Our support teams have been asking for ways to ensure that data has completely synchronized to our corporate datacenter every night.  Unfortunately there isn&#8217;t an easy way to determine this scriptomatically.  Well leave it to me to try some different things and attempt to put SOMETHING in place to do this.</p>
<p>Basically we have remote sites replicating during non-business-hours back to a central &#8220;hub&#8221; DFSR server.  We would then backup this &#8220;hub&#8221; server with our corporate backup infrastructure.  This is a WHOLE lot easier than getting users in remote sites to swap tapes or whatever and send them offsite, etc. </p>
<p>The only way I have been able to determine the state of replication is to query the &#8220;backlog&#8221; of the remote site DFSR servers.  This should tell us how many files are sitting there awaiting replication. DFSRDIAG is a tool that can help us enumerate these files, but then we have to parse out the data.  We also need to know which replication partner, which replicated folder, and which replication group these remote sites belong to.</p>
<p>One way to enumerate that info is through a WMI query.  From the DFSR &#8220;hub&#8221; server you can enumerate all DFSR connections, groups, folders, etc. by running some queries against the &#8220;MicrosoftDFS&#8221; namespace.  This is different from standard WMI queries because the default namespace (cimv2) does not contain any DFSR configuruations.</p>
<p>Once we connect to this namespace, it is a fairly trivial task to cycle through all the connection partners, replication groups, and replicated folders.</p>
<p>We can then run the &#8220;DFSRDIAG&#8221; tool to see how many files are in the backlog.</p>
<p>Once we have determine how many files are out there for each replicated folder, we then write a custom event log entry and have our monitoring tools pick those up.</p>
<p>For this script I have set a threshold of 10 files before writing an &#8220;error&#8221; event log.  This can easily be changed based on your specific needs, though.  </p>
<p>You should also be able to easily customize the eventIDs and source information by modifying the values assigned to those variables.</p>
<p>For actually writing to the event log, I am &#8220;borrowing&#8221; some code my colleauge <a title="Mike Hays' blog site" href="http://blog.mike-hays.net" target="_blank">Mike </a>put together.</p>
<p>Anyway, I think the script is fairly self explanitory.  If you need additionaly info or have questions, please let me know.</p>
<p>Thanks and happy scripting&#8230;</p>
<p>&#8211; Mark</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">## Check-DFSR.ps1 script</span>
<span style="color: #008000;">## Written by: Mark A. Weaver</span>
<span style="color: #008000;">## Site: http://www.vmweaver.com</span>
<span style="color: #008000;">## Version: 2.0</span>
<span style="color: #008000;">## Date: 5/7/2009</span>
<span style="color: #008000;">## Purpose: This script will query the local WMI root for DFS replication groups and folders.  </span>
<span style="color: #008000;">##				It will then run DFS utilities to determine the number of files in the backlog on the</span>
<span style="color: #008000;">##          destination partners in the replication group.</span>
<span style="color: #008000;">##          </span>
<span style="color: #008000;">##          This script was written for the spefic use of being run on a centralized DFSR server</span>
<span style="color: #008000;">##          which acts as the HUB for remote office backups.</span>
<span style="color: #008000;">##         </span>
<span style="color: #008000;">##        </span>
<span style="color: #008000;">##          Monitoring Rules can be setup to collect and report on the events being generated.</span>
<span style="color: #008000;">## </span>
<span style="color: #008000;">##          Event information is written to the Application log using the EventIDs at the bottom.</span>
<span style="color: #008000;">## Input: None</span>
<span style="color: #008000;">#############################</span>
<span style="color: #008000;">## Updates:</span>
<span style="color: #008000;">##  20090408 Weaver: Fixed issue where multiple events are generated throughout the execution</span>
<span style="color: #008000;">##  20090408 Weaver: Added BacklogFileCount to event message</span>
<span style="color: #008000;">##  20090409 Weaver: Fixed list of replication connections issue due to change in replication topology</span>
<span style="color: #008000;">##  20090507 Weaver: Added functionality to return results from all partners in the replication</span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">##</span>
<span style="color: #008000;">######################################################################</span>
<span style="color: #008000;">######################################################################</span>
<span style="color: #008000;"># Write-Event powershell function</span>
<span style="color: #008000;"># Written by Mike Hays</span>
<span style="color: #008000;"># http://blog.mike-hays.net</span>
<span style="color: #008000;">#</span>
<span style="color: #008000;">#</span>
&nbsp;
<span style="color: #0000FF;">function</span> Write<span style="color: pink;">-</span>Event<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;">$Source</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span><span style="color: #0000FF;">throw</span> <span style="color: #800000;">&quot;An event Source must be specified.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$EventId</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span><span style="color: #0000FF;">throw</span> <span style="color: #800000;">&quot;An Event ID must be specified.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span>System.Diagnostics.EventLogEntryType<span style="color: #000000;">&#93;</span> <span style="color: #800080;">$EventType</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span><span style="color: #0000FF;">throw</span> <span style="color: #800000;">&quot;Event EventType must be specified. (Error, Warning, Information, SuccessAudit, FailureAudit)&quot;</span><span style="color: #000000;">&#41;</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;">$Message</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span><span style="color: #0000FF;">throw</span> <span style="color: #800000;">&quot;An event Message must be specified.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span>
	<span style="color: #800080;">$EventLog</span>
<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008000;">#Uncommon event logs can be specified (even custom ones), but since that isn't generally</span>
	<span style="color: #008000;">#the desired result, I prevent that here</span>
	<span style="color: #800080;">$acceptedEventLogs</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Application&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;System&quot;</span>
	<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$eventEventLog</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;">$eventEventLog</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Application&quot;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">elseif</span> <span style="color: #000000;">&#40;</span><span style="color: pink;">!</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$acceptedEventLogs</span> <span style="color: #FF0000;">-icontains</span> <span style="color: #800080;">$eventEventLog</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;This function supports writing to the following event logs:&quot;</span> <span style="color: #800080;">$acceptedEventLogs</span>
		<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Defaulting to Application Eventlog&quot;</span>
		<span style="color: #800080;">$eventEventLog</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Application&quot;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008000;">#Create a .NET object that is connected to the Eventlog</span>
	<span style="color: #800080;">$event</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: pink;">-</span><span style="color: #008080; font-weight: bold;">type</span> System.Diagnostics.Eventlog <span style="color: #008080; font-style: italic;">-argumentlist</span> <span style="color: #800080;">$EventLog</span>
	<span style="color: #008000;">#Define the Source property</span>
	<span style="color: #800080;">$event</span>.Source <span style="color: pink;">=</span> <span style="color: #800080;">$Source</span>
	<span style="color: #008000;">#Write the event to the log</span>
	<span style="color: #800080;">$event</span>.WriteEntry<span style="color: #000000;">&#40;</span><span style="color: #800080;">$Message</span><span style="color: pink;">,</span> <span style="color: #800080;">$EventType</span><span style="color: pink;">,</span> <span style="color: #800080;">$EventId</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;">######################################################################</span>
<span style="color: #008000;">######################################################################</span>
<span style="color: #008000;">## Main </span>
<span style="color: #008000;">## Errors written:</span>
<span style="color: #008000;">##   Log File: Application</span>
<span style="color: #008000;">##   Source: Check-DFSR Script</span>
<span style="color: #008000;">##   ID: 9500 - Lists fully replicated replication folders</span>
<span style="color: #008000;">##   ID: 9501 - Lists replication folders with less than the $BacklogErrorLevel files waiting </span>
<span style="color: #008000;">##   ID: 9502 - Lists replication folders with more than the $BacklogErrorLevel files waiting</span>
<span style="color: #008000;">##   ID: 9503 - If a connection is not pingable, this event is written.</span>
&nbsp;
<span style="color: #800080;">$BacklogErrorLevel</span> <span style="color: pink;">=</span> <span style="color: #804000;">10</span> 
&nbsp;
<span style="color: #800080;">$ComputerName</span> <span style="color: pink;">=</span> <span style="color: #800080;">$env</span>:ComputerName
<span style="color: #008000;">## Query DFSR groups from the local MicrosftDFS WMI namespace.</span>
<span style="color: #800080;">$DFSRGroupWMIQuery</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;SELECT * FROM DfsrReplicationGroupConfig&quot;</span>
<span style="color: #800080;">$RGroups</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-Namespace</span> <span style="color: #800000;">&quot;root\MicrosoftDFS&quot;</span> <span style="color: #008080; font-style: italic;">-Query</span> <span style="color: #800080;">$DFSRGroupWMIQuery</span>
&nbsp;
&nbsp;
<span style="color: #008000;">## Setup my variables</span>
<span style="color: #800080;">$ping</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Net.NetworkInformation.Ping
<span style="color: #800080;">$SuccessAudit</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Null</span>
<span style="color: #800080;">$WarningAudit</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Null</span>
<span style="color: #800080;">$ErrorAudit</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Null</span>
<span style="color: #800080;">$EventSource</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Check-DFSR Script&quot;</span>
<span style="color: #800080;">$SuccessEventID</span> <span style="color: pink;">=</span> <span style="color: #804000;">9500</span>
<span style="color: #800080;">$WarningEventID</span> <span style="color: pink;">=</span> <span style="color: #804000;">9501</span>
<span style="color: #800080;">$ErrorEventID</span> <span style="color: pink;">=</span> <span style="color: #804000;">9502</span>
<span style="color: #800080;">$NoPingEventID</span> <span style="color: pink;">=</span> <span style="color: #804000;">9503</span>
&nbsp;
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Group</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$RGroups</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008000;">## Cycle through all Replication groups found</span>
	<span style="color: #800080;">$DFSRGFoldersWMIQuery</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;SELECT * FROM DfsrReplicatedFolderConfig WHERE ReplicationGroupGUID='&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Group</span>.ReplicationGroupGUID <span style="color: pink;">+</span> <span style="color: #800000;">&quot;'&quot;</span>
	<span style="color: #800080;">$RGFolders</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-Namespace</span> <span style="color: #800000;">&quot;root\MicrosoftDFS&quot;</span> <span style="color: #008080; font-style: italic;">-Query</span> <span style="color: #800080;">$DFSRGFoldersWMIQuery</span>
&nbsp;
	<span style="color: #008000;">## Grab all connections associated with a Replication Group</span>
	<span style="color: #800080;">$DFSRConnectionWMIQuery</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;SELECT * FROM DfsrConnectionConfig WHERE ReplicationGroupGUID='&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Group</span>.ReplicationGroupGUID <span style="color: pink;">+</span> <span style="color: #800000;">&quot;'&quot;</span>
	<span style="color: #800080;">$RGConnections</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-Namespace</span> <span style="color: #800000;">&quot;root\MicrosoftDFS&quot;</span> <span style="color: #008080; font-style: italic;">-Query</span> <span style="color: #800080;">$DFSRConnectionWMIQuery</span>	
	<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Connection</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$RGConnections</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #800080;">$ConnectionName</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Connection</span>.PartnerName.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #800080;">$IsInBound</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Connection</span>.Inbound
		<span style="color: #800080;">$IsEnabled</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Connection</span>.Enabled
&nbsp;
		<span style="color: #008000;">## Do not attempt to look at connections that are Disabled</span>
		<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$IsEnabled</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: #008000;">## If the connection is not ping-able, do not attempt to query it for Backlog info</span>
			<span style="color: #800080;">$Reply</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ping</span>.send<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;$ConnectionName&quot;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$reply</span>.Status <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;Success&quot;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
&nbsp;
&nbsp;
				<span style="color: #008000;">## Cycle through the Replication Folders that are part of the replication group and run DFSRDIAG tool to determine the backlog on the connection partners.</span>
				<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Folder</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$RGFolders</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					<span style="color: #800080;">$RGName</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Group</span>.ReplicationGroupName
					<span style="color: #800080;">$RFName</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Folder</span>.ReplicatedFolderName
&nbsp;
					<span style="color: #008000;">## Determine if current connect is an inbound connection or not, set send/receive members accordingly</span>
					<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$IsInBound</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;">$SendingMember</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ConnectionName</span>
						<span style="color: #800080;">$ReceivingMember</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ComputerName</span>
					<span style="color: #000000;">&#125;</span>
					<span style="color: #0000FF;">else</span>
					<span style="color: #000000;">&#123;</span>
						<span style="color: #800080;">$SendingMember</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ComputerName</span>
						<span style="color: #800080;">$ReceivingMember</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ConnectionName</span>
					<span style="color: #000000;">&#125;</span>
					   <span style="color: #800080;">$Out</span> <span style="color: pink;">=</span> <span style="color: #800080;">$RGName</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;:&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$RFName</span> <span style="color: pink;">+</span>  <span style="color: #800000;">&quot; - S:&quot;</span><span style="color: pink;">+</span><span style="color: #800080;">$SendingMember</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot; R:&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$ReceivingMember</span> 
					   <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$Out</span>
						<span style="color: #008000;">## Execute the dfsrdiag command and get results back in the $Backlog variable</span>
						<span style="color: #800080;">$BLCommand</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;dfsrdiag Backlog /RGName:'&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$RGName</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;' /RFName:'&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$RFName</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;' /SendingMember:&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$SendingMember</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot; /ReceivingMember:&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$ReceivingMember</span>
						<span style="color: #800080;">$Backlog</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Invoke-Expression</span> <span style="color: #008080; font-style: italic;">-Command</span> <span style="color: #800080;">$BLCommand</span>
&nbsp;
						<span style="color: #800080;">$BackLogFilecount</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
						<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$item</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$Backlog</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;">$item</span> <span style="color: #FF0000;">-ilike</span> <span style="color: #800000;">&quot;*Backlog File count*&quot;</span><span style="color: #000000;">&#41;</span>
							<span style="color: #000000;">&#123;</span>
								<span style="color: #800080;">$BacklogFileCount</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Item</span>.Split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
							<span style="color: #000000;">&#125;</span>
&nbsp;
						<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
						<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$BacklogFileCount</span> <span style="color: #FF0000;">-eq</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#41;</span>
						<span style="color: #000000;">&#123;</span>
							<span style="color: #008000;">#Update Success Audit </span>
							<span style="color: #800080;">$SuccessAudit</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$RGName</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;:&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$RFName</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot; is in sync with 0 files in the backlog from &quot;</span><span style="color: pink;">+</span> <span style="color: #800080;">$SendingMember</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot; to &quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$ReceivingMember</span> <span style="color: pink;">+</span><span style="color: #800000;">&quot;.<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span>					
&nbsp;
						<span style="color: #000000;">&#125;</span>
						<span style="color: #0000FF;">elseif</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$BacklogFilecount</span> <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$BacklogErrorLevel</span><span style="color: #000000;">&#41;</span>
						<span style="color: #000000;">&#123;</span>
							<span style="color: #008000;">#Update Warning Audit</span>
							<span style="color: #800080;">$WarningAudit</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$RGName</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;:&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$RFName</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot; has &quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$BacklogFileCount</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot; files in the backlog from &quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$SendingMember</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot; to &quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$ReceivingMember</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;.<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span>
						<span style="color: #000000;">&#125;</span>
						<span style="color: #0000FF;">else</span>
						<span style="color: #000000;">&#123;</span>
							<span style="color: #008000;">#Update Error Audit</span>
							<span style="color: #800080;">$ErrorAudit</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$RGName</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;:&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$RFName</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot; has &quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$BacklogFilecount</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot; files in the backlog from &quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$SendingMember</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot; to &quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$ReceivingMember</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;.<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span>
						<span style="color: #000000;">&#125;</span>
						<span style="color: #008000;">#Write-Host + $Folder.ReplicatedFolderName &quot;- &quot; $BackLogFilecount -foregroundcolor $FGColor</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0000FF;">else</span>
				<span style="color: #000000;">&#123;</span> 
				<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$ConnectionName</span> <span style="color: #800000;">&quot;is not pingable&quot;</span> 
				<span style="color: #800080;">$NoPingMessage</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Server &quot;</span><span style="color: #800000;">&quot;&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$ConnectionName</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #800000;">&quot; could not be reached.<span style="color: #008080; font-weight: bold;">`n</span>Please verify it is on the network and pingable.&quot;</span>
				Write<span style="color: pink;">-</span>Event <span style="color: #800080;">$EventSource</span> <span style="color: #800080;">$NoPingEventID</span> <span style="color: #800000;">&quot;Warning&quot;</span> <span style="color: #800080;">$NoPingMessage</span> <span style="color: #800000;">&quot;Application&quot;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
<span style="color: #008000;">## Write my events to the local Application log.</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$SuccessAudit</span> <span style="color: #FF0000;">-ne</span> <span style="color: #800080;">$Null</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	Write<span style="color: pink;">-</span>Event <span style="color: #800080;">$EventSource</span> <span style="color: #800080;">$SuccessEventID</span> <span style="color: #800000;">&quot;Information&quot;</span> <span style="color: #800080;">$SuccessAudit</span> <span style="color: #800000;">&quot;Application&quot;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$WarningAudit</span> <span style="color: #FF0000;">-ne</span> <span style="color: #800080;">$Null</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	Write<span style="color: pink;">-</span>Event <span style="color: #800080;">$EventSource</span> <span style="color: #800080;">$WarningEventID</span> <span style="color: #800000;">&quot;Warning&quot;</span> <span style="color: #800080;">$WarningAudit</span> <span style="color: #800000;">&quot;Application&quot;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$ErrorAudit</span> <span style="color: #FF0000;">-ne</span> <span style="color: #800080;">$Null</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	Write<span style="color: pink;">-</span>Event <span style="color: #800080;">$EventSource</span> <span style="color: #800080;">$ErrorEventID</span> <span style="color: #800000;">&quot;Error&quot;</span> <span style="color: #800080;">$ErrorAudit</span> <span style="color: #800000;">&quot;Application&quot;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://vmweaver.com/index.php/2009/04/powershell-and-dfsr/feed/</wfw:commentRss>
		<slash:comments>81</slash:comments>
		</item>
	</channel>
</rss>

