<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Business and Information Technology Tangents &#187; Powershell Tangents</title>
	<atom:link href="http://bittangents.com/category/powershell-tangents/feed/" rel="self" type="application/rss+xml" />
	<link>http://bittangents.com</link>
	<description>Business and Information Technology Tangents is dedicated to providing quality content while informing the world about technology.</description>
	<lastBuildDate>Fri, 27 Apr 2012 21:02:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='bittangents.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Business and Information Technology Tangents &#187; Powershell Tangents</title>
		<link>http://bittangents.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://bittangents.com/osd.xml" title="Business and Information Technology Tangents" />
	<atom:link rel='hub' href='http://bittangents.com/?pushpress=hub'/>
		<item>
		<title>System Center Configuration manager (SCCM) 2007 R3 &#8211; Device Discovery Issue / Health Check script</title>
		<link>http://bittangents.com/2012/04/18/system-center-configuration-manager-sccm-2007-r3-device-discovery-issue-health-check-script/</link>
		<comments>http://bittangents.com/2012/04/18/system-center-configuration-manager-sccm-2007-r3-device-discovery-issue-health-check-script/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 21:42:59 +0000</pubDate>
		<dc:creator>brentblawat</dc:creator>
				<category><![CDATA[Powershell Tangents]]></category>

		<guid isPermaLink="false">https://brentblawat.wordpress.com/?p=536</guid>
		<description><![CDATA[By: Brenton Blawat A large hospital recently had been experiencing issues with their SCCM Server replication and SCCM Remote Console. Initially, they started to notice slow package replication which quickly expanded to the following list: SCCM 2007 Remote Console Loading Slowly SCCM 2007 Remote Console Not Connecting to Remote Clients SCCM 2007 Packages Taking Hours [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=536&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>By: Brenton Blawat</strong></p>
<p>A large hospital recently had been experiencing issues with their SCCM Server replication and SCCM Remote Console. Initially, they started to notice slow package replication which quickly expanded to the following list:</p>
<ul>
<li>SCCM 2007 Remote Console Loading Slowly </li>
<li>SCCM 2007 Remote Console Not Connecting to Remote Clients </li>
<li>SCCM 2007 Packages Taking Hours for Replication </li>
<li>SCCM 2007 ‘My’ Computer freezing on server / drive not accessible </li>
<li>SCCM 2007 Explorer Crashes on Central Server / Cannot View Inboxes\Auth\ </li>
</ul>
<h2></h2>
<h1>SCCM Configuration</h1>
<p><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="SCCMSetup" border="0" alt="SCCMSetup" src="http://brentblawat.files.wordpress.com/2012/04/sccmsetup_thumb.jpg?w=375&h=247" width="375" height="247" /></p>
<p>The hospital, with over 12,000 computers, hosted a central server and two primary child sites (as shown above). These servers are all Windows Server 2008 R2 servers and had been running functionally since February of 2012.&#160; Site_101 and Site_102 were both configured to replicate their record sets to the central server.</p>
<p>Please note that there is an additional WDS deployment server which is not shown in the above image as it is irrelevant to this discussion.</p>
<h1>SCCM issue: Device Discovery Records build-up</h1>
<p>&#160;</p>
<p><a href="http://brentblawat.files.wordpress.com/2012/04/sccmdiscoverypattern.jpg"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="SCCMDiscoveryPattern" border="0" alt="SCCMDiscoveryPattern" src="http://brentblawat.files.wordpress.com/2012/04/sccmdiscoverypattern_thumb.jpg?w=563&h=296" width="563" height="296" /></a> </p>
<p>After a bit of research, it was determined that the issues above had to do with the configuration of the <strong>Discovery Methods. </strong>Site_100, Site_101, and Site_102 were configured to perform <strong><u>full</u></strong> Active Directory System Discoveries (DDR Record Generation) every 5 minutes (relevant to their respective AD hierarchy). </p>
<p>In the hospital’s case, the (DDR) records were being created by the two children sites and pushed up to the Central Server. The Central Server had to <strong>#1</strong> process its own device discovery records, <strong>#2</strong> process Site_101 and Site_102 discovery records. The Central Server could not process the DDRs as fast as they were being generated. Subsequently, the directory started to fill up with old device discovery information. By the time the device discovery record issue was discovered, the <em>%drive%</em>\Program Files (x86)\Microsoft Configuration Manager\inboxes\auth\ddm.box\ inbox had almost <u><strong>22.1 million device discovery records</strong></u>. </p>
<p>The build up of files had the following effects on the server:</p>
<ul>
<li><strong>Disk Contention </strong>– Files were being written and deleted (delete is a disk write as well!) causing the disk queue to be in the upwards of 200 operations. This simply crippled the use of that RAID drive which affected all SCCM components rendering the Central Server useless. </li>
<li><strong>Windows Indexing Issues</strong> – Due to the mere number of files (22.1 million), in addition to keeping track of those being added / removed, the indexing service could not keep up with the operations of the server. This was the cause of Windows Explorer to hanging and crashing as it was attempting to index the files. </li>
</ul>
<h1>The Resolution</h1>
<p>To resolve the issue, the server was restarted in safe mode and the ddm.box was renamed to ddm.box.old. The files in ddm.box.old should have been deleted at that point, however, due to the number of files, it would have extended the outage. To return operations of the SCCM Central server, the server was restarted and the deletion was done outside of safe mode.</p>
<p>After the reboot completed, the Discovery Methods were immediately adjusted to the following:</p>
<ul>
<li><strong>Central Server Site_100 Device Discovery was turned OFF</strong> – The Central Server was purposed for only reporting and configuration of packages. The child will provide the device discovery records to the Central Server. </li>
<li><strong>Site_101 Reconfigured – </strong>The full device discovery methods of the respective active directory OUs were adjusted to once a day at 12:00am (outside of the backup window). Delta discoveries have been enabled for every 30 minutes. </li>
<li><strong>Site_102 Reconfigured – </strong>The full device discovery methods of the respective active directory OUs were adjusted to once a day at 11:00pm (outside of the backup window). Delta discoveries have been enabled for every 30 minutes. </li>
</ul>
<p>To delete the files in the ddm.box.old directory the following was performed:</p>
<ul>
<li><strong>Disable AV Scanning of Inboxes-</strong>&#160; Symantec Endpoint Protection was scanning all files on the server. A directory exclusion of <em>%drive%</em>\Program Files (x86)\Microsoft Configuration Manager\inboxes\ was created to optimize operations on the server (and help with the deletion process) </li>
<li><strong>Batch Deletion of Files–</strong> Unfortunately, Windows Explorer could not delete the files from the directory. Even when indexing is turned off, it will index the files prior to deletion.
<ul>
<li>Created a new .bat file changing the directory to <em>%drive%</em>\Program Files (x86)\Microsoft Configuration Manager\inboxes\auth\ddm.box\ </li>
<li>Issued the following command del *.* /f/s </li>
<li>This command took <u><strong>5 days</strong></u> to execute. </li>
</ul>
</li>
<li><strong>Defragmentation of the drive – </strong>After the deletion, the SCCM drive had 28% fragmentation and a disk defragmentation was run. </li>
</ul>
<p>&#160;</p>
<h2></h2>
<h1>Preventing and Monitoring the Issue</h1>
<p>In order to monitor further file backups on the server, a new PowerShell script was created to monitor files. The script can be found here<strong>:</strong> <a href="http://bittangents.com/2012/04/18/powershell-script-sccm-2007-health-check/">PowerShell Script – SCCM 2007 Health Check</a></p>
<p>This script is designed to run in two modes:</p>
<ol>
<li>Morning General Health Status – To report warning level and critical level errors.</li>
<li>Hourly Health Check – To report only critical level errors. </li>
</ol>
<p>This script is used along with Task Scheduler which executes these programs on intervals. Please note that it was determined that if the file level for the hospital’s environment that anything over 20,000 files constitutes a critical error OR if a service is not running as expected.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentblawat.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentblawat.wordpress.com/536/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brentblawat.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brentblawat.wordpress.com/536/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brentblawat.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brentblawat.wordpress.com/536/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brentblawat.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brentblawat.wordpress.com/536/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brentblawat.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brentblawat.wordpress.com/536/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brentblawat.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brentblawat.wordpress.com/536/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brentblawat.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brentblawat.wordpress.com/536/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=536&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittangents.com/2012/04/18/system-center-configuration-manager-sccm-2007-r3-device-discovery-issue-health-check-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fd28fc9e2db7e469f8237a6d55fba2b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentblawat</media:title>
		</media:content>

		<media:content url="http://brentblawat.files.wordpress.com/2012/04/sccmsetup_thumb.jpg" medium="image">
			<media:title type="html">SCCMSetup</media:title>
		</media:content>

		<media:content url="http://brentblawat.files.wordpress.com/2012/04/sccmdiscoverypattern_thumb.jpg" medium="image">
			<media:title type="html">SCCMDiscoveryPattern</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell Script &#8211; SCCM 2007 Health Check</title>
		<link>http://bittangents.com/2012/04/18/powershell-script-sccm-2007-health-check/</link>
		<comments>http://bittangents.com/2012/04/18/powershell-script-sccm-2007-health-check/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 21:34:41 +0000</pubDate>
		<dc:creator>brentblawat</dc:creator>
				<category><![CDATA[Powershell Tangents]]></category>

		<guid isPermaLink="false">https://brentblawat.wordpress.com/?p=529</guid>
		<description><![CDATA[By: Brenton Blawat System Center Configuration Manager 2007 is an extremely powerful tool that, when configured correctly, will provide deployment and reporting capabilities for your organization. As explored in a previous article (located here), there are situations where a health check is helpful to ensure stability of the SCCM 2007 servers. The below PowerShell Script [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=529&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>By: Brenton Blawat</strong></p>
<p>System Center Configuration Manager 2007 is an extremely powerful tool that, when configured correctly, will provide deployment and reporting capabilities for your organization. As explored in a previous article <a href="http://bittangents.com/2012/04/18/system-center-configuration-manager-sccm-2007-r3-device-discovery-issue-health-check-script/">(located here),</a> there are situations where a health check is helpful to ensure stability of the SCCM 2007 servers.</p>
<p>The below PowerShell Script was designed to perform two operations:</p>
<ul>
<li>Morning Report – To run as a scheduled task in the morning and email a distribution group (or individual email) if anything is potentially going wrong. (Warning Level to Critical Levels). </li>
<li>Hourly Status Check – To run as a scheduled task every hour and email a distribution group (or individual email) if anything is Critically wrong. (Critical Level Only). </li>
</ul>
<p>The script performs the following at a high level:</p>
<ol>
<li>Loads the SCCM.XML File </li>
<li>Determines from the SCCM.XML file where SCCM is installed. </li>
<li>Using the SCCM.XML File, reads through the unique ID’s under the ‘filecheck’ and determines the file count for those directories. </li>
<li>Using the SCCM.XML File, reads through the unique ID’s under the ‘servicecheck’ and determines the startup state, and running state of the services required for SCCM. </li>
<li>Sends an email to the specified address with any warning or critical messages. </li>
</ol>
<h2>To run the script and Email Warning AND Critical Messages:</h2>
<p>(What we use every 7am in the morning)</p>
<p><strong>powershell.exe directory\sccm_health.ps1 –reporttype “MorningReport”</strong></p>
<h2>To run the script and Email Critical Messages:</h2>
<p>(What we use every hour at the top of every hour)</p>
<p><strong>powershell.exe directory\sccm_health.ps1</strong></p>
<h2>To send all results regardless of report type:</h2>
<p>Modify SCCM_Health.ps1 line 18 to be <strong><span class="kwrd">if</span> (-not $debug) { $debug = 1 }</strong></p>
<p>Alternatively you can run: </p>
<p><strong>powershell.exe directory\sccm_health.ps1 –debug 1</strong></p>
<p>&#160;</p>
<h2>PowerShell Code SCCM 2007 Health Check</h2>
<p><a href="http://www.brentblawat.com/blog/codesnippets/SCCM_Health.zip"><strong>Download Code</strong></a></p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span><span class="rem">###############################################</span></pre>
<pre><span class="lnum">   2:  </span><span class="rem">## SCCM 2007 R3 HEALTH CHECK</span></pre>
<pre><span class="lnum">   3:  </span><span class="rem">##</span></pre>
<pre><span class="lnum">   4:  </span><span class="rem">## By: Brenton Blawat</span></pre>
<pre><span class="lnum">   5:  </span><span class="rem">## Website Reference: Http://www.bittangents.com</span></pre>
<pre><span class="lnum">   6:  </span><span class="rem">##</span></pre>
<pre><span class="lnum">   7:  </span><span class="rem">##</span></pre>
<pre><span class="lnum">   8:  </span><span class="rem">## Please note that sccm.xml needs to be in the same directory as this script.</span></pre>
<pre><span class="lnum">   9:  </span><span class="rem">##</span></pre>
<pre><span class="lnum">  10:  </span><span class="rem">## Please also note that `r`n means &quot;return -- new line&quot; for the email formatting.</span></pre>
<pre><span class="lnum">  11:  </span><span class="rem">##</span></pre>
<pre><span class="lnum">  12:  </span><span class="rem">###############################################</span></pre>
<pre><span class="lnum">  13:  </span>&#160;</pre>
<pre><span class="lnum">  14:  </span><span class="rem"># Take any input triggers as the report type MorningReport</span></pre>
<pre><span class="lnum">  15:  </span><span class="kwrd">param</span>($reporttype,$debug)</pre>
<pre><span class="lnum">  16:  </span>&#160;</pre>
<pre><span class="lnum">  17:  </span><span class="rem">#To Turn On Debugging Level Emails Change From 0 to 1 or use the above trigger</span></pre>
<pre><span class="lnum">  18:  </span><span class="kwrd">if</span> (-not $debug) { $debug = 0 }</pre>
<pre><span class="lnum">  19:  </span>&#160;</pre>
<pre><span class="lnum">  20:  </span><span class="rem"># If the report does not contain the following triggers, only output the debugging level and/or on Critical Issues.</span></pre>
<pre><span class="lnum">  21:  </span><span class="kwrd">if</span> ($reporttype -notcontains <span class="str">&quot;MorningReport&quot;</span>) { </pre>
<pre><span class="lnum">  22:  </span>    $reporttype = <span class="str">&quot;&quot;</span></pre>
<pre><span class="lnum">  23:  </span>}</pre>
<pre><span class="lnum">  24:  </span>&#160;</pre>
<pre><span class="lnum">  25:  </span><span class="rem">#Get Computer Name For Email Generation</span></pre>
<pre><span class="lnum">  26:  </span>$CmpName = [System.Net.DNS]::GetHostName()</pre>
<pre><span class="lnum">  27:  </span>&#160;</pre>
<pre><span class="lnum">  28:  </span><span class="rem">#Function to create a new email</span></pre>
<pre><span class="lnum">  29:  </span><span class="kwrd">function</span> send-email { <span class="kwrd">param</span>($emailFrom,$emailTo,$subject,$body)</pre>
<pre><span class="lnum">  30:  </span>    <span class="rem">#Specify the Server Name</span></pre>
<pre><span class="lnum">  31:  </span>    $smtpServer = <span class="str">&quot;Your.Fully.Qualified.Email.Server&quot;</span></pre>
<pre><span class="lnum">  32:  </span>    <span class="rem">#Setup the Email Connection Object</span></pre>
<pre><span class="lnum">  33:  </span>    $smtp = new-object Net.Mail.SmtpClient($smtpServer)</pre>
<pre><span class="lnum">  34:  </span>    <span class="rem">#Send the Email as Specified</span></pre>
<pre><span class="lnum">  35:  </span>    $smtp.Send($emailFrom, $emailTo, $subject, $body)</pre>
<pre><span class="lnum">  36:  </span>}</pre>
<pre><span class="lnum">  37:  </span>&#160;</pre>
<pre><span class="lnum">  38:  </span><span class="rem"># This function will count the files in the directories specified in the XML document.</span></pre>
<pre><span class="lnum">  39:  </span>Function get-filecount { <span class="kwrd">param</span>($inbox, $directory)</pre>
<pre><span class="lnum">  40:  </span>    <span class="rem"># Generate the count of the child item.</span></pre>
<pre><span class="lnum">  41:  </span>    $count = (Get-Childitem $directory).count</pre>
<pre><span class="lnum">  42:  </span>    </pre>
<pre><span class="lnum">  43:  </span>    <span class="rem"># If the Count is less than 1000 AND</span></pre>
<pre><span class="lnum">  44:  </span>    <span class="rem"># If the script is being run as a MorningReport or in debug mode Return Informational.</span></pre>
<pre><span class="lnum">  45:  </span>    If ($count <span class="preproc">-lt</span> 1000) { <span class="kwrd">if</span> ($reporttype <span class="preproc">-eq</span> <span class="str">&quot;MorningReport&quot;</span> -or $debug <span class="preproc">-eq</span> <span class="str">&quot;1&quot;</span>) { <span class="kwrd">return</span> <span class="str">&quot;Informational: $inbox File Count is: $Count `r`n&quot;</span> } }</pre>
<pre><span class="lnum">  46:  </span>    <span class="rem"># If the count is greater than 1000</span></pre>
<pre><span class="lnum">  47:  </span>    If ($count <span class="preproc">-gt</span> 1000) { </pre>
<pre><span class="lnum">  48:  </span>        <span class="rem"># If the count is greater than 10000 Return a Critical Message</span></pre>
<pre><span class="lnum">  49:  </span>        If ($count <span class="preproc">-gt</span> 10000) { </pre>
<pre><span class="lnum">  50:  </span>            <span class="kwrd">return</span> <span class="str">&quot;***** CRITICAL *****: $inbox File Count is: $Count `r`n&quot;</span></pre>
<pre><span class="lnum">  51:  </span>        }        </pre>
<pre><span class="lnum">  52:  </span>        <span class="rem">#if it is less than 10000, Return a Warning Message</span></pre>
<pre><span class="lnum">  53:  </span>        Else { <span class="kwrd">if</span> ($reporttype <span class="preproc">-eq</span> <span class="str">&quot;MorningReport&quot;</span> -or $debug <span class="preproc">-eq</span> <span class="str">&quot;1&quot;</span>) { <span class="kwrd">return</span> <span class="str">&quot;***** WARNING *****: $inbox File Count is: $Count `r`n&quot;</span>  } }</pre>
<pre><span class="lnum">  54:  </span>    }</pre>
<pre><span class="lnum">  55:  </span>}</pre>
<pre><span class="lnum">  56:  </span>&#160;</pre>
<pre><span class="lnum">  57:  </span><span class="rem"># This Function Will Get the Service Status of a service on a computer. It will determine what the startup type</span></pre>
<pre><span class="lnum">  58:  </span><span class="rem"># is and what the current status of the service is.</span></pre>
<pre><span class="lnum">  59:  </span><span class="kwrd">function</span> get-servicestatus { <span class="kwrd">param</span>($name,$service,$health)</pre>
<pre><span class="lnum">  60:  </span>    </pre>
<pre><span class="lnum">  61:  </span>    <span class="rem">#Create the Result Array Variable</span></pre>
<pre><span class="lnum">  62:  </span>    $serviceresult = @()</pre>
<pre><span class="lnum">  63:  </span>    </pre>
<pre><span class="lnum">  64:  </span>    <span class="rem"># Query the Service Startup Mode of the local computer</span></pre>
<pre><span class="lnum">  65:  </span>    $servicestart = Get-WmiObject -Query <span class="str">&quot;Select StartMode From Win32_Service Where Name='$service'&quot;</span> -ErrorVariable Err -ErrorAction SilentlyContinue</pre>
<pre><span class="lnum">  66:  </span>    </pre>
<pre><span class="lnum">  67:  </span>    <span class="rem">#if there is an error -- report it here -- This is useful if RPC is not functional or the service is not responding</span></pre>
<pre><span class="lnum">  68:  </span>    <span class="kwrd">if</span> ($err) { </pre>
<pre><span class="lnum">  69:  </span>        $serviceresult += <span class="str">&quot;***** CRITICAL *****: Error Getting Service Start Information: $err `r`n&quot;</span></pre>
<pre><span class="lnum">  70:  </span>        [string]$servicemode = <span class="str">&quot;(Cannot Determine Start Mode)&quot;</span></pre>
<pre><span class="lnum">  71:  </span>    }</pre>
<pre><span class="lnum">  72:  </span>    <span class="rem">#This will ensure that the service startup type IS what is specified in the SCCM File. If not -- Throw an error.</span></pre>
<pre><span class="lnum">  73:  </span>    <span class="kwrd">if</span> (-not $servicestart) { </pre>
<pre><span class="lnum">  74:  </span>        $serviceresult += <span class="str">&quot;***** CRITICAL *****: Error Getting Service Start Information: $err `r`n&quot;</span></pre>
<pre><span class="lnum">  75:  </span>        [string]$servicemode = <span class="str">&quot;(Cannot Determine Start Mode)&quot;</span></pre>
<pre><span class="lnum">  76:  </span>    }</pre>
<pre><span class="lnum">  77:  </span>    <span class="rem"># If it is functional, Return the start mode.</span></pre>
<pre><span class="lnum">  78:  </span>    Else { [string]$servicemode = $servicestart.startmode }</pre>
<pre><span class="lnum">  79:  </span>    </pre>
<pre><span class="lnum">  80:  </span>    <span class="rem"># This query will get the current running state of the service.    </span></pre>
<pre><span class="lnum">  81:  </span>    $service = get-service -name $service -ErrorVariable Err -ErrorAction SilentlyContinue</pre>
<pre><span class="lnum">  82:  </span>    <span class="rem"># This is the error handling. If the service is not responding -- it will report the error here.</span></pre>
<pre><span class="lnum">  83:  </span>    <span class="kwrd">if</span> ($err) { </pre>
<pre><span class="lnum">  84:  </span>        $serviceresult += <span class="str">&quot;***** CRITICAL *****: Error Getting Service Status Information: $err `r`n&quot;</span></pre>
<pre><span class="lnum">  85:  </span>        [string]$service = <span class="str">&quot;(Cannot Determine Service Running Status)&quot;</span></pre>
<pre><span class="lnum">  86:  </span>    }    </pre>
<pre><span class="lnum">  87:  </span>    <span class="rem"># If it is functional, Return the running mode.</span></pre>
<pre><span class="lnum">  88:  </span>    Else { [string]$servicestatus = $service.status }</pre>
<pre><span class="lnum">  89:  </span> </pre>
<pre><span class="lnum">  90:  </span>    </pre>
<pre><span class="lnum">  91:  </span>       </pre>
<pre><span class="lnum">  92:  </span>    <span class="rem"># If the XML File Reads Started/Automatic for the Service to be Healthy Proceed with the following</span></pre>
<pre><span class="lnum">  93:  </span>    <span class="kwrd">if</span> ($health <span class="preproc">-eq</span> <span class="str">&quot;Started/Automatic&quot;</span>) {</pre>
<pre><span class="lnum">  94:  </span>        <span class="rem"># Is the current State Set to Auto as expected? If not -- throw Exception</span></pre>
<pre><span class="lnum">  95:  </span>        <span class="kwrd">if</span> ($servicemode <span class="preproc">-notmatch</span> <span class="str">&quot;Auto&quot;</span>) {</pre>
<pre><span class="lnum">  96:  </span>            $serviceresult += <span class="str">&quot;***** CRITICAL *****: $Name Service Start Mode Set to: $servicemode and Expecting to be $health `r`n&quot;</span></pre>
<pre><span class="lnum">  97:  </span>        }</pre>
<pre><span class="lnum">  98:  </span>        <span class="rem">#Report Healthy for MorningReport and Debug.</span></pre>
<pre><span class="lnum">  99:  </span>        <span class="kwrd">else</span> {</pre>
<pre><span class="lnum"> 100:  </span>            <span class="kwrd">if</span> ($reporttype <span class="preproc">-eq</span> <span class="str">&quot;MorningReport&quot;</span> -or $debug <span class="preproc">-eq</span> <span class="str">&quot;1&quot;</span>) { $serviceresult += <span class="str">&quot;Informational: $Name Service Start Mode Set to: $servicemode `r`n&quot;</span> }</pre>
<pre><span class="lnum"> 101:  </span>        }</pre>
<pre><span class="lnum"> 102:  </span>        <span class="rem">### Phase 2 ###</span></pre>
<pre><span class="lnum"> 103:  </span>        <span class="rem"># Is the service currently running as expected? If Not -- throw Exception    </span></pre>
<pre><span class="lnum"> 104:  </span>        <span class="kwrd">if</span> ($servicestatus <span class="preproc">-notmatch</span> <span class="str">&quot;Running&quot;</span>) {</pre>
<pre><span class="lnum"> 105:  </span>            $serviceresult += <span class="str">&quot;***** CRITICAL *****: $Name Service Running Status is currently: $servicemode and Expecting to be $health `r`n&quot;</span></pre>
<pre><span class="lnum"> 106:  </span>        }</pre>
<pre><span class="lnum"> 107:  </span>        <span class="rem">#Report Healthy for MorningReport and Debug.</span></pre>
<pre><span class="lnum"> 108:  </span>        <span class="kwrd">else</span> {</pre>
<pre><span class="lnum"> 109:  </span>            <span class="kwrd">if</span> ($reporttype <span class="preproc">-eq</span> <span class="str">&quot;MorningReport&quot;</span> -or $debug <span class="preproc">-eq</span> <span class="str">&quot;1&quot;</span>) { $serviceresult += <span class="str">&quot;Informational: $Name Service Running Status is currently: $servicestatus `r`n&quot;</span> }</pre>
<pre><span class="lnum"> 110:  </span>        }</pre>
<pre><span class="lnum"> 111:  </span>    }</pre>
<pre><span class="lnum"> 112:  </span>    </pre>
<pre><span class="lnum"> 113:  </span>    <span class="rem">#If the XML File Reads Manual Startup for Service to be Healthy Proceed with the following</span></pre>
<pre><span class="lnum"> 114:  </span>    <span class="kwrd">if</span> ($health <span class="preproc">-eq</span> <span class="str">&quot;Manual&quot;</span>) {</pre>
<pre><span class="lnum"> 115:  </span>            <span class="rem"># If the service is not set to manual -- throw exception.</span></pre>
<pre><span class="lnum"> 116:  </span>            <span class="kwrd">if</span> ($servicemode <span class="preproc">-notmatch</span> <span class="str">&quot;Manual&quot;</span>) {</pre>
<pre><span class="lnum"> 117:  </span>                $serviceresult += <span class="str">&quot;***** CRITICAL *****: $Name Service Start Mode Set to: $servicemode and Expecting to be $health `r`n&quot;</span></pre>
<pre><span class="lnum"> 118:  </span>            }</pre>
<pre><span class="lnum"> 119:  </span>            <span class="rem">#Report Healthy for MorningReport and Debug.</span></pre>
<pre><span class="lnum"> 120:  </span>            <span class="kwrd">else</span> {</pre>
<pre><span class="lnum"> 121:  </span>                <span class="kwrd">if</span> ($reporttype <span class="preproc">-eq</span> <span class="str">&quot;MorningReport&quot;</span> -or $debug <span class="preproc">-eq</span> <span class="str">&quot;1&quot;</span>) { $serviceresult += <span class="str">&quot;Informational: $Name Service Start Mode Set to: $servicemode `r`n&quot;</span> }</pre>
<pre><span class="lnum"> 122:  </span>            }</pre>
<pre><span class="lnum"> 123:  </span>    } </pre>
<pre><span class="lnum"> 124:  </span>    </pre>
<pre><span class="lnum"> 125:  </span>    <span class="rem">#If the XML File Reads Disabled Startup for Service to be Healthy Proceed with the following</span></pre>
<pre><span class="lnum"> 126:  </span>    <span class="kwrd">if</span> ($health <span class="preproc">-eq</span> <span class="str">&quot;Disabled&quot;</span>) {</pre>
<pre><span class="lnum"> 127:  </span>        <span class="rem"># If the service is not set to disabled -- throw exception.</span></pre>
<pre><span class="lnum"> 128:  </span>        <span class="kwrd">if</span> ($servicemode <span class="preproc">-notmatch</span> <span class="str">&quot;Disabled&quot;</span>) {</pre>
<pre><span class="lnum"> 129:  </span>            $serviceresult += <span class="str">&quot;***** CRITICAL *****: $Name Service Start Mode Set to: $servicemode and Expecting to be $health `r`n&quot;</span></pre>
<pre><span class="lnum"> 130:  </span>        }</pre>
<pre><span class="lnum"> 131:  </span>        <span class="rem">#Report Healthy for MorningReport and Debug.        </span></pre>
<pre><span class="lnum"> 132:  </span>        <span class="kwrd">else</span> {</pre>
<pre><span class="lnum"> 133:  </span>            <span class="kwrd">if</span> ($reporttype <span class="preproc">-eq</span> <span class="str">&quot;MorningReport&quot;</span> -or $debug <span class="preproc">-eq</span> <span class="str">&quot;1&quot;</span>) { $serviceresult += <span class="str">&quot;Informational: $Name Service Start Mode Set to: $servicemode `r`n&quot;</span> }</pre>
<pre><span class="lnum"> 134:  </span>        }</pre>
<pre><span class="lnum"> 135:  </span>    }</pre>
<pre><span class="lnum"> 136:  </span>    <span class="kwrd">return</span> $serviceresult    </pre>
<pre><span class="lnum"> 137:  </span>}</pre>
<pre><span class="lnum"> 138:  </span>&#160;</pre>
<pre><span class="lnum"> 139:  </span><span class="rem"># This function will read the XML data</span></pre>
<pre><span class="lnum"> 140:  </span><span class="kwrd">function</span> Get-XMLData { <span class="kwrd">param</span>($XMLExtract,$XMLvar)</pre>
<pre><span class="lnum"> 141:  </span>    </pre>
<pre><span class="lnum"> 142:  </span>    <span class="rem">#Result Variable</span></pre>
<pre><span class="lnum"> 143:  </span>    $dataresult = @()</pre>
<pre><span class="lnum"> 144:  </span>    </pre>
<pre><span class="lnum"> 145:  </span>    <span class="rem"># Get the content from the sccm.xml file</span></pre>
<pre><span class="lnum"> 146:  </span>    $xml = [xml] (get-content <span class="str">&quot;sccm.xml&quot;</span>)</pre>
<pre><span class="lnum"> 147:  </span>    </pre>
<pre><span class="lnum"> 148:  </span>    <span class="rem"># Start the DOT Notation Loop for the data specified to extract</span></pre>
<pre><span class="lnum"> 149:  </span>    ForEach($node <span class="kwrd">in</span> $xml.GetElementsByTagName(<span class="str">&quot;$xmlextract&quot;</span>)) {</pre>
<pre><span class="lnum"> 150:  </span>        $id = $node.Id</pre>
<pre><span class="lnum"> 151:  </span>        ForEach($item <span class="kwrd">in</span> $node) {</pre>
<pre><span class="lnum"> 152:  </span>            <span class="rem">#Grab the SCCM Path Data if Requested</span></pre>
<pre><span class="lnum"> 153:  </span>            <span class="kwrd">if</span> ($xmlextract <span class="preproc">-eq</span> <span class="str">&quot;SCCMPATH&quot;</span>) {</pre>
<pre><span class="lnum"> 154:  </span>                $xmlpath = $item.objloc</pre>
<pre><span class="lnum"> 155:  </span>                <span class="kwrd">return</span> $xmlpath</pre>
<pre><span class="lnum"> 156:  </span>            }</pre>
<pre><span class="lnum"> 157:  </span>            <span class="rem"># Start the File Check Process if Requested</span></pre>
<pre><span class="lnum"> 158:  </span>            <span class="kwrd">if</span> ($xmlextract <span class="preproc">-eq</span> <span class="str">&quot;filecheck&quot;</span>) {</pre>
<pre><span class="lnum"> 159:  </span>                $xmlname = $item.name</pre>
<pre><span class="lnum"> 160:  </span>                $xmldirpath = $installdir + $item.objloc</pre>
<pre><span class="lnum"> 161:  </span>                $dataresult += get-filecount $xmlname $xmldirpath</pre>
<pre><span class="lnum"> 162:  </span>            </pre>
<pre><span class="lnum"> 163:  </span>            }</pre>
<pre><span class="lnum"> 164:  </span>            <span class="rem"># Start the Service Check Process if Requested</span></pre>
<pre><span class="lnum"> 165:  </span>            <span class="kwrd">if</span> ($xmlextract <span class="preproc">-eq</span> <span class="str">&quot;servicecheck&quot;</span>) {</pre>
<pre><span class="lnum"> 166:  </span>                $xmlname = $item.name</pre>
<pre><span class="lnum"> 167:  </span>                $xmlservice = $item.service</pre>
<pre><span class="lnum"> 168:  </span>                $xmlhealth = $item.healthy</pre>
<pre><span class="lnum"> 169:  </span>                $dataresult += get-servicestatus $xmlname $xmlservice $xmlhealth</pre>
<pre><span class="lnum"> 170:  </span>                        </pre>
<pre><span class="lnum"> 171:  </span>            }</pre>
<pre><span class="lnum"> 172:  </span>        }</pre>
<pre><span class="lnum"> 173:  </span>    }</pre>
<pre><span class="lnum"> 174:  </span><span class="rem">#Return Results</span></pre>
<pre><span class="lnum"> 175:  </span><span class="kwrd">return</span> $dataresult</pre>
<pre><span class="lnum"> 176:  </span>}</pre>
<pre><span class="lnum"> 177:  </span>&#160;</pre>
<pre><span class="lnum"> 178:  </span><span class="rem">#Create the Report Variable and header</span></pre>
<pre><span class="lnum"> 179:  </span>$report = @()</pre>
<pre><span class="lnum"> 180:  </span>&#160;</pre>
<pre><span class="lnum"> 181:  </span><span class="rem">#Header to Email</span></pre>
<pre><span class="lnum"> 182:  </span>$report += <span class="str">&quot;------------------------------------------`r`n&quot;</span></pre>
<pre><span class="lnum"> 183:  </span>$report += <span class="str">&quot;-------------SCCM HEALTH CHECK------------`r`n&quot;</span></pre>
<pre><span class="lnum"> 184:  </span>$report += <span class="str">&quot;------------------------------------------`r`n&quot;</span></pre>
<pre><span class="lnum"> 185:  </span>&#160;</pre>
<pre><span class="lnum"> 186:  </span>$report += <span class="str">&quot;`r`n&quot;</span></pre>
<pre><span class="lnum"> 187:  </span>&#160;</pre>
<pre><span class="lnum"> 188:  </span><span class="rem">#Get the Installation Directory From XML File</span></pre>
<pre><span class="lnum"> 189:  </span>$installdir = Get-XMLData SCCMPATH</pre>
<pre><span class="lnum"> 190:  </span>&#160;</pre>
<pre><span class="lnum"> 191:  </span><span class="rem">#Header to Email</span></pre>
<pre><span class="lnum"> 192:  </span>$report += <span class="str">&quot;`r`n&quot;</span></pre>
<pre><span class="lnum"> 193:  </span>$report += <span class="str">&quot;-------------SCCM HEALTH CHECK [File Check]------------`r`n&quot;</span></pre>
<pre><span class="lnum"> 194:  </span>$report += <span class="str">&quot;`r`n&quot;</span></pre>
<pre><span class="lnum"> 195:  </span>&#160;</pre>
<pre><span class="lnum"> 196:  </span><span class="rem"># Execute the File Check Process and store in the report variable</span></pre>
<pre><span class="lnum"> 197:  </span>$report += Get-XMLData filecheck</pre>
<pre><span class="lnum"> 198:  </span>&#160;</pre>
<pre><span class="lnum"> 199:  </span>$report += <span class="str">&quot;`r`n&quot;</span></pre>
<pre><span class="lnum"> 200:  </span>$report += <span class="str">&quot;-------------SCCM HEALTH CHECK [Services Check]------------`r`n&quot;</span></pre>
<pre><span class="lnum"> 201:  </span>$report += <span class="str">&quot;`r`n&quot;</span></pre>
<pre><span class="lnum"> 202:  </span>&#160;</pre>
<pre><span class="lnum"> 203:  </span><span class="rem"># Execute the Service Check Process and Store the report in variable</span></pre>
<pre><span class="lnum"> 204:  </span>$report += Get-XMLData servicecheck</pre>
<pre><span class="lnum"> 205:  </span>&#160;</pre>
<pre><span class="lnum"> 206:  </span><span class="rem"># If the report contains a warning or critical item, Send Email.</span></pre>
<pre><span class="lnum"> 207:  </span><span class="kwrd">if</span> ($report -MATCH <span class="str">&quot;WARNING&quot;</span> -OR $report -MATCH <span class="str">&quot;CRITICAL&quot;</span>) {</pre>
<pre><span class="lnum"> 208:  </span>&#160;</pre>
<pre><span class="lnum"> 209:  </span>  <span class="rem">#Send A New Email. Format: new-email From To Subject Body</span></pre>
<pre><span class="lnum"> 210:  </span>  $cpuemail = $CmpName + <span class="str">&quot;@yourcompanynamehere.com&quot;</span></pre>
<pre><span class="lnum"> 211:  </span>  send-email $cpuemail <span class="str">&quot;YourDistributionGroupGoesHere@YourCompanyNameHere.com&quot;</span> <span class="str">&quot;$CmpName Health Summary Report (Errors Detected)&quot;</span> $report</pre>
<pre><span class="lnum"> 212:  </span>}</pre>
<pre><span class="lnum"> 213:  </span>&#160;</pre>
<pre><span class="lnum"> 214:  </span><span class="rem"># List out Report for Visual Effect</span></pre>
<pre><span class="lnum"> 215:  </span>$report</pre>
</div>
<p>.csharpcode, .csharpcode pre<br />
{<br />
	font-size: small;<br />
	color: black;<br />
	font-family: consolas, &#8220;Courier New&#8221;, courier, monospace;<br />
	background-color: #ffffff;<br />
	/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
	background-color: #f4f4f4;<br />
	width: 100%;<br />
	margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; }</p>
<p>&#160;</p>
<h2>XML File: SCCM.XML Explained</h2>
<p>Without explaining how to setup and use XML Files – this section will explain how to add and remove objects to the XML File.</p>
<p><a href="http://brentblawat.files.wordpress.com/2012/04/sccmpath.jpg"><img style="display:inline;border-width:0;" title="Sccmpath" border="0" alt="Sccmpath" src="http://brentblawat.files.wordpress.com/2012/04/sccmpath_thumb.jpg?w=543&h=77" width="543" height="77" /></a> </p>
<p>The above graphic depicts the formatting of the location where SCCM is installed. This is valuable in the case that different servers have different installation paths. This should only contain <strong>ONE VALUE</strong>. Enter the location of SCCM 2007.</p>
<p><a href="http://brentblawat.files.wordpress.com/2012/04/sccmfilesetup.jpg"><img style="display:inline;border-width:0;" title="Sccmfilesetup" border="0" alt="Sccmfilesetup" src="http://brentblawat.files.wordpress.com/2012/04/sccmfilesetup_thumb.jpg?w=651&h=117" width="651" height="117" /></a> </p>
<p>The above graphic depicts the formatting of the location of the directories which the PowerShell script will count files. This path is relevant to the SCCMPATH + Object Location. The above example would be interpreted as:</p>
<p>“d:\Program Files (x86)\Microsoft Configuration manager\Inboxes\auth\dataldr.box”</p>
<p>The ‘name’ field is only as a short name that will be included in the email. Anything you put in this field will help the person receiving the email to quickly determine what is the problematic directory location.</p>
<p>* Object location should<strong> NOT</strong> <strong>start or end</strong> with ‘\’. </p>
<p>* Do not forget to increment the ‘id’ with every new line. Duplicate ids will result in an error.</p>
<p><a href="http://brentblawat.files.wordpress.com/2012/04/servicesetup.jpg"><img style="display:inline;border-width:0;" title="service Setup" border="0" alt="service Setup" src="http://brentblawat.files.wordpress.com/2012/04/servicesetup_thumb.jpg?w=650&h=124" width="650" height="124" /></a> </p>
<p>The above graphic depicts the formatting of the services that should be checked during the health check. Anything you put in this field will help the person receiving the email to quickly determine what is the problematic service.</p>
<p>The ‘service’ field is the Service name under service.msc. These can be the name of the service, but often are different.</p>
<p>The ‘Healthy’ field is the state the service should be in. There are three states that are approved by this script: Started/Automatic; Manual; Disabled. To ensure proper operations, ensure that the healthy state is one of these three. </p>
<h2>XML File: SCCM.XML Contents</h2>
<p><a href="http://www.brentblawat.com/blog/codesnippets/SCCM_Health.zip"><strong>Download Code</strong></a></p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span>&lt;?xml version=<span class="str">&quot;1.0&quot;</span>?&gt;</pre>
<pre><span class="lnum">   2:  </span>&#160;</pre>
<pre><span class="lnum">   3:  </span>&lt;SCCM2007Health&gt;</pre>
<pre><span class="lnum">   4:  </span>  &lt;SCCMPATH id=<span class="str">&quot;0&quot;</span> objloc=<span class="str">&quot;D:\Program Files (x86)\&quot;&gt;&lt;/SCCMPATH&gt;</pre>
<pre><span class="lnum">   5:  </span>&#160;</pre>
<pre><span class="lnum">   6:  </span>  &lt;filecheck id=&quot;</span>0<span class="str">&quot; name=&quot;</span>Dataldr.box<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\dataldr.box<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">   7:  </span>  &lt;filecheck id=&quot;</span>1<span class="str">&quot; name=&quot;</span>Dataldr.box\Process<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\dataldr.box\process<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">   8:  </span>  &lt;filecheck id=&quot;</span>2<span class="str">&quot; name=&quot;</span>Dataldr.box\BADMIFS<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\dataldr.box\BADMIFS<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">   9:  </span>  &lt;filecheck id=&quot;</span>3<span class="str">&quot; name=&quot;</span>Dataldr.box\bad<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\dataldr.box\bad<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  10:  </span>  &lt;filecheck id=&quot;</span>4<span class="str">&quot; name=&quot;</span>Dataldr.box\Retry<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\dataldr.box\retry<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  11:  </span>  </pre>
<pre><span class="lnum">  12:  </span>  &lt;filecheck id=&quot;</span>5<span class="str">&quot; name=&quot;</span>Ddm.box<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\ddm.box<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  13:  </span>  &lt;filecheck id=&quot;</span>6<span class="str">&quot; name=&quot;</span>Ddm.box\Bad<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\ddm.box\bad<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  14:  </span>  &lt;filecheck id=&quot;</span>7<span class="str">&quot; name=&quot;</span>Ddm.box\BAD_DDRS<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\ddm.box\BAD_DDRS<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  15:  </span>  &lt;filecheck id=&quot;</span>8<span class="str">&quot; name=&quot;</span>Ddm.box\regreq<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\ddm.box\regreq<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  16:  </span>&#160;</pre>
<pre><span class="lnum">  17:  </span>  &lt;filecheck id=&quot;</span>9<span class="str">&quot; name=&quot;</span>sinv.box<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\sinv.box<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  18:  </span>  &lt;filecheck id=&quot;</span>10<span class="str">&quot; name=&quot;</span>sinv.box\bad<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\sinv.box\bad<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  19:  </span>  &lt;filecheck id=&quot;</span>11<span class="str">&quot; name=&quot;</span>sinv.box\Orphans<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\sinv.box\Orphans<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  20:  </span>  &lt;filecheck id=&quot;</span>12<span class="str">&quot; name=&quot;</span>sinv.box\Retry<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\sinv.box\Retry<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  21:  </span>&#160;</pre>
<pre><span class="lnum">  22:  </span>  &lt;filecheck id=&quot;</span>13<span class="str">&quot; name=&quot;</span>statesys.box<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\statesys.box<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  23:  </span>  &lt;filecheck id=&quot;</span>14<span class="str">&quot; name=&quot;</span>statesys.box\corrupt<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\statesys.box\corrupt<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  24:  </span>  &lt;filecheck id=&quot;</span>15<span class="str">&quot; name=&quot;</span>statesys.box\incoming<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\statesys.box\incoming<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  25:  </span>  &lt;filecheck id=&quot;</span>16<span class="str">&quot; name=&quot;</span>statesys.box\outgoing<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\statesys.box\outgoing<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  26:  </span>  &lt;filecheck id=&quot;</span>17<span class="str">&quot; name=&quot;</span>statesys.box\process<span class="str">&quot; objloc=&quot;</span>Microsoft Configuration Manager\inboxes\auth\statesys.box\process<span class="str">&quot;&gt;&lt;/filecheck&gt;</pre>
<pre><span class="lnum">  27:  </span>  </pre>
<pre><span class="lnum">  28:  </span>  &lt;servicecheck id=&quot;</span>0<span class="str">&quot; name=&quot;</span>SMS Executive<span class="str">&quot; service=&quot;</span>SMS_EXECUTIVE<span class="str">&quot; healthy=&quot;</span>Started/Automatic<span class="str">&quot;&gt;&lt;/servicecheck&gt;</pre>
<pre><span class="lnum">  29:  </span>  &lt;servicecheck id=&quot;</span>1<span class="str">&quot; name=&quot;</span>SMS Site Backup<span class="str">&quot; service=&quot;</span>SMS_SITE_BACKUP<span class="str">&quot; healthy=&quot;</span>Manual<span class="str">&quot;&gt;&lt;/servicecheck&gt;</pre>
<pre><span class="lnum">  30:  </span>  &lt;servicecheck id=&quot;</span>2<span class="str">&quot; name=&quot;</span>SMS Site Component Manager<span class="str">&quot; service=&quot;</span>SMS_SITE_COMPONENT_MANAGER<span class="str">&quot; healthy=&quot;</span>Started/Automatic<span class="str">&quot;&gt;&lt;/servicecheck&gt;</pre>
<pre><span class="lnum">  31:  </span>  &lt;servicecheck id=&quot;</span>3<span class="str">&quot; name=&quot;</span>SMS Site SQL Backup<span class="str">&quot; service=&quot;</span>SMS_SITE_SQL_BACKUP<span class="str">&quot; healthy=&quot;</span>Started/Automatic<span class="str">&quot;&gt;&lt;/servicecheck&gt;</pre>
<pre><span class="lnum">  32:  </span>  &lt;servicecheck id=&quot;</span>4<span class="str">&quot; name=&quot;</span>SMS Site VSS Writer<span class="str">&quot; service=&quot;</span>SMS_SITE_VSS_WRITER<span class="str">&quot; healthy=&quot;</span>Started/Automatic<span class="str">&quot;&gt;&lt;/servicecheck&gt;</pre>
<pre><span class="lnum">  33:  </span>&#160;</pre>
<pre><span class="lnum">  34:  </span>  &lt;servicecheck id=&quot;</span>5<span class="str">&quot; name=&quot;</span>SQL Server (MSSQLSERVER)<span class="str">&quot; service=&quot;</span>MSSQLSERVER<span class="str">&quot; healthy=&quot;</span>Started/Automatic<span class="str">&quot;&gt;&lt;/servicecheck&gt;</pre>
<pre><span class="lnum">  35:  </span>  &lt;servicecheck id=&quot;</span>6<span class="str">&quot; name=&quot;</span>SQL Server Agent (MSSQLSERVER)<span class="str">&quot; service=&quot;</span>SQLSERVERAGENT<span class="str">&quot; healthy=&quot;</span>Started/Automatic<span class="str">&quot;&gt;&lt;/servicecheck&gt;</pre>
<pre><span class="lnum">  36:  </span>  &lt;servicecheck id=&quot;</span>7<span class="str">&quot; name=&quot;</span>SQL Server Browser<span class="str">&quot; service=&quot;</span>SQLBrowser<span class="str">&quot; healthy=&quot;</span>Disabled<span class="str">&quot;&gt;&lt;/servicecheck&gt;</pre>
<pre><span class="lnum">  37:  </span>  &lt;servicecheck id=&quot;</span>8<span class="str">&quot; name=&quot;</span>SQL Server Reporting Services (MSSQLSERVER)<span class="str">&quot; service=&quot;</span>ReportServer<span class="str">&quot; healthy=&quot;</span>Started/Automatic<span class="str">&quot;&gt;&lt;/servicecheck&gt;</pre>
<pre><span class="lnum">  38:  </span>  &lt;servicecheck id=&quot;</span>9<span class="str">&quot; name=&quot;</span>SQL Server VSS Writer<span class="str">&quot; service=&quot;</span>SQLWriter<span class="str">&quot; healthy=&quot;</span>Started/Automatic<span class="str">&quot;&gt;&lt;/servicecheck&gt;</pre>
<pre><span class="lnum">  39:  </span>&#160;</pre>
<pre><span class="lnum">  40:  </span>  &lt;servicecheck id=&quot;</span>10<span class="str">&quot; name=&quot;</span>Volume Shadow Copy<span class="str">&quot; service=&quot;</span>VSS<span class="str">&quot; healthy=&quot;</span>Manual&quot;&gt;&lt;/servicecheck&gt;</pre>
<pre><span class="lnum">  41:  </span>&#160;</pre>
<pre><span class="lnum">  42:  </span>&lt;/SCCM2007Health&gt;</pre>
</div>
<p>.csharpcode, .csharpcode pre<br />
{<br />
	font-size: small;<br />
	color: black;<br />
	font-family: consolas, &#8220;Courier New&#8221;, courier, monospace;<br />
	background-color: #ffffff;<br />
	/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
	background-color: #f4f4f4;<br />
	width: 100%;<br />
	margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; }</p>
<p>&#160;</p>
<p><strong>Happy Coding!</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentblawat.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentblawat.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brentblawat.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brentblawat.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brentblawat.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brentblawat.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brentblawat.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brentblawat.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brentblawat.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brentblawat.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brentblawat.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brentblawat.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brentblawat.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brentblawat.wordpress.com/529/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=529&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittangents.com/2012/04/18/powershell-script-sccm-2007-health-check/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fd28fc9e2db7e469f8237a6d55fba2b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentblawat</media:title>
		</media:content>

		<media:content url="http://brentblawat.files.wordpress.com/2012/04/sccmpath_thumb.jpg" medium="image">
			<media:title type="html">Sccmpath</media:title>
		</media:content>

		<media:content url="http://brentblawat.files.wordpress.com/2012/04/sccmfilesetup_thumb.jpg" medium="image">
			<media:title type="html">Sccmfilesetup</media:title>
		</media:content>

		<media:content url="http://brentblawat.files.wordpress.com/2012/04/servicesetup_thumb.jpg" medium="image">
			<media:title type="html">service Setup</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell queryService&#8211;Wait for a Dependency Starting Service</title>
		<link>http://bittangents.com/2011/06/03/powershell-queryservicewait-for-a-dependency-starting-service/</link>
		<comments>http://bittangents.com/2011/06/03/powershell-queryservicewait-for-a-dependency-starting-service/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 01:13:42 +0000</pubDate>
		<dc:creator>brentblawat</dc:creator>
				<category><![CDATA[Powershell Tangents]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[start]]></category>
		<category><![CDATA[status]]></category>
		<category><![CDATA[wait]]></category>

		<guid isPermaLink="false">https://brentblawat.wordpress.com/2011/06/03/powershell-queryservicewait-for-a-dependency-starting-service/</guid>
		<description><![CDATA[By: Brenton Blawat There have been several occasions while scripting in PowerShell that the script is dependent on a specific service in the running state. A good example is the need to wait for the WMI Service to startup prior to making a WMI call, or SQL Server where when you restart the services, you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=516&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>By: Brenton Blawat</strong></p>
<p>There have been several occasions while scripting in PowerShell that the script is dependent on a specific service in the running state. A good example is the need to wait for the WMI Service to startup prior to making a WMI call, or SQL Server where when you restart the services, you have to wait for the services to be in a running state before you can execute commands.</p>
<p>The following function solves this issue. It also displays the proper implementation of a PowerShell wait timer to wait for a service to become operational before continuing in the script.</p>
<h2>PowerShell Code Waiting for Service</h2>
<p><a href="http://www.brentblawat.com/blog/codesnippets/QueryService.ps1"><strong>Download Code</strong></a></p>
<p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#039;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#008000;"># This Function Will Query A Dependancy Service and wait until the timer expires OR for the service to start.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> <span style="color:#0000ff;">function</span> QueryService { <span style="color:#0000ff;">param</span>($Service,$timer1)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span>     $success = <span style="color:#006080;">&quot;&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum4">   4:</span>     write-host <span style="color:#006080;">&quot;Waiting on $Service Service...&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum5">   5:</span>     </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum6">   6:</span>     <span style="color:#008000;"># Create a for loop to INC a timer Every Second</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum7">   7:</span>     <span style="color:#0000ff;">for</span> ($b=1; $b <span style="color:#cc6633;">-lt</span> $timer1; $b++) {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum8">   8:</span>             $servicestat = get-service $Service</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum9">   9:</span>             $status = $servicestat.status</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum10">  10:</span>             $b2 = $timer1 - $b</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum11">  11:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum12">  12:</span>             <span style="color:#008000;"># Determine the Percent Complete for the seconds.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum13">  13:</span>             $percent = $b * (100 / $timer1)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum14">  14:</span>             </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum15">  15:</span>             <span style="color:#008000;"># Display the progress on the Screen</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum16">  16:</span>             Write-Progress -Activity <span style="color:#006080;">&quot;Waiting on $Service Service...&quot;</span> -PercentComplete $percent -CurrentOperation <span style="color:#006080;">&quot;$b2 Seconds Remaining&quot;</span> -Status <span style="color:#006080;">&quot;Current WMI Status: $status&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum17">  17:</span>             </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum18">  18:</span>             <span style="color:#008000;"># Determine if the Process is Running. If not, reloop. If so exit loop.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum19">  19:</span>             <span style="color:#0000ff;">if</span> ($status <span style="color:#cc6633;">-eq</span> <span style="color:#006080;">&quot;Running&quot;</span>) {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum20">  20:</span>                 write-host <span style="color:#006080;">&quot;$Service Service Started Successfully: $status in $b Seconds&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum21">  21:</span>                 [int]$b = $timer1    </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum22">  22:</span>                     $success = <span style="color:#006080;">&quot;yes&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum23">  23:</span>                 </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum24">  24:</span>                 <span style="color:#008000;"># Tells the Loop to Stop Incrementing as the Service is running</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum25">  25:</span>                 Write-Progress -Activity <span style="color:#006080;">&quot;Completed&quot;</span> -Status <span style="color:#006080;">&quot;Current $Service Status: $status in $b Seconds&quot;</span> -Completed </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum26">  26:</span>                 </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum27">  27:</span>             }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum28">  28:</span>         </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum29">  29:</span>         <span style="color:#008000;"># Start-Sleep is available for the write-progress. Its value is in seconds.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum30">  30:</span>         start-sleep 1</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum31">  31:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum32">  32:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum33">  33:</span>     <span style="color:#008000;"># The script will now stop as the above loop has meet its time criteria and the success is not set to yes.time has expired.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum34">  34:</span>     <span style="color:#0000ff;">if</span> ($success <span style="color:#cc6633;">-ne</span> <span style="color:#006080;">&quot;yes&quot;</span>) { </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum35">  35:</span>         write-host <span style="color:#006080;">&quot;ERROR in Script: $Service Service Did Not Start In $timer1 Seconds. Status: $status&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum36">  36:</span>         <span style="color:#008000;"># Stop the Script</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum37">  37:</span>        BREAK</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum38">  38:</span>     } </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum39">  39:</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum40">  40:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum41">  41:</span> <span style="color:#008000;"># The service must be the actual executible name, not the friendly name</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum42">  42:</span> <span style="color:#008000;"># The Below Examples are Querying SQL Services for startup waiting 120 seconds for a timeout.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum43">  43:</span> QueryService <span style="color:#006080;">&quot;SQLServerAgent&quot;</span> <span style="color:#006080;">&quot;120&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum44">  44:</span> QueryService <span style="color:#006080;">&quot;MSSQLSERVER&quot;</span> <span style="color:#006080;">&quot;120&quot;</span></pre>
<p><!--CRLF--></div>
</p></div>
</p>
<p>The implementation of the QueryService is pretty straight forward. The syntax is </p>
<p>QueryServices “EXENAME” “TIMEOUT_IN_SECONDS”</p>
<p>The exe name is what is found in the Services Management Console listed under the &quot;Service Name”. Using the “Display Name” will not work with this function.</p>
<p><strong>Please note:</strong> If a service is running, there will be approximately a second delay in the script while the system is verifying if the service is running. This is a small sacrifice for error handling in the instance that the service may not be running. </p>
<p>Happy Coding!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentblawat.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentblawat.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brentblawat.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brentblawat.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brentblawat.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brentblawat.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brentblawat.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brentblawat.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brentblawat.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brentblawat.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brentblawat.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brentblawat.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brentblawat.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brentblawat.wordpress.com/516/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=516&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittangents.com/2011/06/03/powershell-queryservicewait-for-a-dependency-starting-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fd28fc9e2db7e469f8237a6d55fba2b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentblawat</media:title>
		</media:content>
	</item>
		<item>
		<title>Powershell Import-GPO : The Data Is Invalid Fixed</title>
		<link>http://bittangents.com/2010/04/20/powershell-import-gpo-the-data-is-invalid-fixed/</link>
		<comments>http://bittangents.com/2010/04/20/powershell-import-gpo-the-data-is-invalid-fixed/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 20:05:51 +0000</pubDate>
		<dc:creator>brentblawat</dc:creator>
				<category><![CDATA[Powershell Tangents]]></category>

		<guid isPermaLink="false">http://brentblawat.wordpress.com/2010/04/20/powershell-import-gpo-the-data-is-invalid-fixed/</guid>
		<description><![CDATA[By: Brenton Blawat This article is to aid those who are receiving the “Data is Invalid” error message in Powershell on Windows Server 2008 R2. This issue occurs while trying to import policies from one domain into their a different domain using a migration table. This issue has to do with the migration table editor [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=471&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>By: Brenton Blawat</strong></p>
<p>This article is to aid those who are receiving the “Data is Invalid” error message in Powershell on Windows Server 2008 R2. This issue occurs while trying to import policies from one domain into their a different domain using a migration table. This issue has to do with the migration table editor referring to the “Pre-Windows 2000 Username” to migrate users instead of their Standard Username.</p>
<p><strong>Syntax of Command Used for Error:</strong></p>
<blockquote><p>Import-GPO –BackupID {GUIDGOESHERE} –TargetName “Default_AccountingPolicy” –path “c:\scriptloc\” –MigrationTable “C:\scriptloc\DefaultMig.migtable” –CreateIfNeeded | Out-Null</p>
</blockquote>
<p><strong>Error:</strong></p>
<blockquote><p>“ Import-GPO : The Data is invalid. (Exception from HRESULT: 0x8007000D) “</p>
</blockquote>
<p><strong>Solution:</strong></p>
<p>The issue has to do with creating Users and User Groups without the ‘SAMACCOUNTNAME’ field while coding with Powershell. Windows Server 2008 R2 generates a unique Pre-2000 username starting with ‘$’ and a series of numbers following. When using the ‘-migrationtable’ trigger, it causes import-gpo cmdlet to validate the “destination users” PRIOR to importing the group policy. If it cannot resolve the User or User group, it will cause the ‘’HRESULT error’.</p>
<p>The following lines were added to the Powershell Script for creating a User Group, which corrected this issue:</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#039;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#008000;"># Where $objworker was the AD method and $ADobjname was the name of the user / group</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> $objworker.put(<span style="color:#006080;">&quot;sAMAccountName&quot;</span>, <span style="color:#006080;">&quot;$ADobjname&quot;</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span> $objworker.SetInfo()</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>Depending on your network, the <strong>fix </strong>can be done in two ways:</p>
<ol>
<li>Ensure the “Pre-Windows 2000 name” is the same as the “Standard Windows Name” </li>
<li>Correct the Migration Table to Use the Pre-Windows 2000 Names for the ‘Destination’ </li>
</ol>
<p><strong>Simple fix </strong>– just wish that the error would be more like “Errors in Migration Table”. The error message of “The Data Is Invalid “ is useless in my opinion. </p>
<p>Happy Coding!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentblawat.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentblawat.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brentblawat.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brentblawat.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brentblawat.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brentblawat.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brentblawat.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brentblawat.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brentblawat.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brentblawat.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brentblawat.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brentblawat.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brentblawat.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brentblawat.wordpress.com/471/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=471&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittangents.com/2010/04/20/powershell-import-gpo-the-data-is-invalid-fixed/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fd28fc9e2db7e469f8237a6d55fba2b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentblawat</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell Script: Encrypting / Decrypting A String &#8211; Function Encrypt-String</title>
		<link>http://bittangents.com/2010/03/20/powershell-script-encrypting-decrypting-a-string-function-encrypt-string/</link>
		<comments>http://bittangents.com/2010/03/20/powershell-script-encrypting-decrypting-a-string-function-encrypt-string/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 15:40:26 +0000</pubDate>
		<dc:creator>brentblawat</dc:creator>
				<category><![CDATA[Powershell Tangents]]></category>

		<guid isPermaLink="false">http://brentblawat.wordpress.com/2010/03/20/powershell-script-encrypting-decrypting-a-string-function-encrypt-string/</guid>
		<description><![CDATA[By: Brenton Blawat The encryption and decryption of strings is essential when creating an enterprise product that has clear text passwords. This function displays how to encrypt and decrypt a string using Powershell using Richard’s code located at http://poshcode.org/116. While I found his code very useful, he didn’t explain the syntax and is why I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=468&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>By: Brenton Blawat</strong></p>
<p>The encryption and decryption of strings is essential when creating an enterprise product that has clear text passwords. This function displays how to encrypt and decrypt a string using Powershell using Richard’s code located at <a title="http://poshcode.org/116" href="http://poshcode.org/116">http://poshcode.org/116</a>. While I found his code very useful, he didn’t explain the syntax and is why I am reposting this with the proper information. </p>
<p>I also decided to make this into an endless loop for an administrator to use to encrypt multiple passwords in a row. I found this to be useful as I never had to encrypt just one password. </p>
<h2></h2>
<h2>Important for your security!!</h2>
<p>In order to ensure your application is safe from an attacker be certain to perform each of the following:</p>
<p>1.&#160; Change the $salt variable and $init variables. These variables should be at least 8 characters long but should be changed or your application is subject to a brute force attack if someone determines you are using my code!</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#0000ff;">function</span> Encrypt-String($String, $Passphrase, $salt=<span style="color:#006080;">&quot;SaltCrypto&quot;</span>, $init=<span style="color:#006080;">&quot;IV_Password&quot;</span>, [<span style="color:#0000ff;">switch</span>]$arrayOutput)</pre>
<p><!--CRLF--></div>
</div>
<p>2.&#160; Change the Passphrase that is passed into the function. I suggest a 12-18 character Passphrase to prevent the above brute force attack.</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> $encrypted = Encrypt-String $string <span style="color:#006080;">&quot;MyStrongPassword&quot;</span></pre>
<p><!--CRLF--></div>
</div>
<p>3.&#160; Be sure to pass the right Passphrase into the function for decryption. If you pass the wrong key into the function, you will not get the correct password returned from the function.</p>
<h2>Function for Encrypting / Decrypting A String in PowerShell</h2>
<p><strong><a href="http://www.brentblawat.com/blog/codesnippets/EncryptDecryptString.PS1" target="_blank">Download PS1 Here</a></strong></p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;height:1839px;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#008000;">#################</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> <span style="color:#008000;"># Powershell Allows The Loading of .NET Assemblies</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span> <span style="color:#008000;"># Load the Security assembly to use with this script </span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum4">   4:</span> <span style="color:#008000;">#################</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum5">   5:</span> [Reflection.Assembly]::LoadWithPartialName(<span style="color:#006080;">&quot;System.Security&quot;</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum6">   6:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum7">   7:</span> <span style="color:#008000;">#################</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum8">   8:</span> <span style="color:#008000;"># This function is to Encrypt A String.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum9">   9:</span> <span style="color:#008000;"># $string is the string to encrypt, $passphrase is a second security &quot;password&quot; that has to be passed to decrypt.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum10">  10:</span> <span style="color:#008000;"># $salt is used during the generation of the crypto password to prevent password guessing.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum11">  11:</span> <span style="color:#008000;"># $init is used to compute the crypto hash -- a checksum of the encryption</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum12">  12:</span> <span style="color:#008000;">#################</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum13">  13:</span> <span style="color:#0000ff;">function</span> Encrypt-String($String, $Passphrase, $salt=<span style="color:#006080;">&quot;SaltCrypto&quot;</span>, $init=<span style="color:#006080;">&quot;IV_Password&quot;</span>, [<span style="color:#0000ff;">switch</span>]$arrayOutput)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum14">  14:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum15">  15:</span>     <span style="color:#008000;"># Create a COM Object for RijndaelManaged Cryptography</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum16">  16:</span>     $r = new-Object System.Security.Cryptography.RijndaelManaged</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum17">  17:</span>     <span style="color:#008000;"># Convert the Passphrase to UTF8 Bytes</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum18">  18:</span>     $pass = [Text.Encoding]::UTF8.GetBytes($Passphrase)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum19">  19:</span>     <span style="color:#008000;"># Convert the Salt to UTF Bytes</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum20">  20:</span>     $salt = [Text.Encoding]::UTF8.GetBytes($salt)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum21">  21:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum22">  22:</span>     <span style="color:#008000;"># Create the Encryption Key using the passphrase, salt and SHA1 algorithm at 256 bits</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum23">  23:</span>     $r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, <span style="color:#006080;">&quot;SHA1&quot;</span>, 5).GetBytes(32) <span style="color:#008000;">#256/8</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum24">  24:</span>     <span style="color:#008000;"># Create the Intersecting Vector Cryptology Hash with the init</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum25">  25:</span>     $r.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum26">  26:</span>     </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum27">  27:</span>     <span style="color:#008000;"># Starts the New Encryption using the Key and IV   </span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum28">  28:</span>     $c = $r.CreateEncryptor()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum29">  29:</span>     <span style="color:#008000;"># Creates a MemoryStream to do the encryption in</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum30">  30:</span>     $ms = new-Object IO.MemoryStream</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum31">  31:</span>     <span style="color:#008000;"># Creates the new Cryptology Stream --&gt; Outputs to $MS or Memory Stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum32">  32:</span>     $cs = new-Object Security.Cryptography.CryptoStream $ms,$c,<span style="color:#006080;">&quot;Write&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum33">  33:</span>     <span style="color:#008000;"># Starts the new Cryptology Stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum34">  34:</span>     $sw = new-Object IO.StreamWriter $cs</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum35">  35:</span>     <span style="color:#008000;"># Writes the string in the Cryptology Stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum36">  36:</span>     $sw.Write($String)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum37">  37:</span>     <span style="color:#008000;"># Stops the stream writer</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum38">  38:</span>     $sw.Close()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum39">  39:</span>     <span style="color:#008000;"># Stops the Cryptology Stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum40">  40:</span>     $cs.Close()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum41">  41:</span>     <span style="color:#008000;"># Stops writing to Memory</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum42">  42:</span>     $ms.Close()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum43">  43:</span>     <span style="color:#008000;"># Clears the IV and HASH from memory to prevent memory read attacks</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum44">  44:</span>     $r.Clear()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum45">  45:</span>     <span style="color:#008000;"># Takes the MemoryStream and puts it to an array</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum46">  46:</span>     [byte[]]$result = $ms.ToArray()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum47">  47:</span>     <span style="color:#008000;"># Converts the array from Base 64 to a string and returns</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum48">  48:</span>     <span style="color:#0000ff;">return</span> [Convert]::ToBase64String($result)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum49">  49:</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum50">  50:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum51">  51:</span> <span style="color:#0000ff;">function</span> Decrypt-String($Encrypted, $Passphrase, $salt=<span style="color:#006080;">&quot;SaltCrypto&quot;</span>, $init=<span style="color:#006080;">&quot;IV_Password&quot;</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum52">  52:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum53">  53:</span>     <span style="color:#008000;"># If the value in the Encrypted is a string, convert it to Base64</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum54">  54:</span>     <span style="color:#0000ff;">if</span>($Encrypted <span style="color:#cc6633;">-is</span> [string]){</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum55">  55:</span>         $Encrypted = [Convert]::FromBase64String($Encrypted)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum56">  56:</span>        }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum57">  57:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum58">  58:</span>     <span style="color:#008000;"># Create a COM Object for RijndaelManaged Cryptography</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum59">  59:</span>     $r = new-Object System.Security.Cryptography.RijndaelManaged</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum60">  60:</span>     <span style="color:#008000;"># Convert the Passphrase to UTF8 Bytes</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum61">  61:</span>     $pass = [Text.Encoding]::UTF8.GetBytes($Passphrase)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum62">  62:</span>     <span style="color:#008000;"># Convert the Salt to UTF Bytes</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum63">  63:</span>     $salt = [Text.Encoding]::UTF8.GetBytes($salt)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum64">  64:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum65">  65:</span>     <span style="color:#008000;"># Create the Encryption Key using the passphrase, salt and SHA1 algorithm at 256 bits</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum66">  66:</span>     $r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, <span style="color:#006080;">&quot;SHA1&quot;</span>, 5).GetBytes(32) <span style="color:#008000;">#256/8</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum67">  67:</span>     <span style="color:#008000;"># Create the Intersecting Vector Cryptology Hash with the init</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum68">  68:</span>     $r.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum69">  69:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum70">  70:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum71">  71:</span>     <span style="color:#008000;"># Create a new Decryptor</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum72">  72:</span>     $d = $r.CreateDecryptor()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum73">  73:</span>     <span style="color:#008000;"># Create a New memory stream with the encrypted value.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum74">  74:</span>     $ms = new-Object IO.MemoryStream @(,$Encrypted)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum75">  75:</span>     <span style="color:#008000;"># Read the new memory stream and read it in the cryptology stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum76">  76:</span>     $cs = new-Object Security.Cryptography.CryptoStream $ms,$d,<span style="color:#006080;">&quot;Read&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum77">  77:</span>     <span style="color:#008000;"># Read the new decrypted stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum78">  78:</span>     $sr = new-Object IO.StreamReader $cs</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum79">  79:</span>     <span style="color:#008000;"># Return from the function the stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum80">  80:</span>     Write-Output $sr.ReadToEnd()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum81">  81:</span>     <span style="color:#008000;"># Stops the stream    </span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum82">  82:</span>     $sr.Close()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum83">  83:</span>     <span style="color:#008000;"># Stops the crypology stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum84">  84:</span>     $cs.Close()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum85">  85:</span>     <span style="color:#008000;"># Stops the memory stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum86">  86:</span>     $ms.Close()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum87">  87:</span>     <span style="color:#008000;"># Clears the RijndaelManaged Cryptology IV and Key</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum88">  88:</span>     $r.Clear()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum89">  89:</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum90">  90:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum91">  91:</span> <span style="color:#008000;"># This clears the screen of the output from the loading of the assembly.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum92">  92:</span> cls</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum93">  93:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum94">  94:</span> <span style="color:#008000;"># $me will never = 1, so It will run indefinately</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum95">  95:</span> $me = 0</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum96">  96:</span>     write-host <span style="color:#006080;">&quot;To End This Application, Close the Window&quot;</span>    </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum97">  97:</span>     Write-host <span style="color:#006080;">&quot;&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum98">  98:</span> do</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum99">  99:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum100"> 100:</span>     <span style="color:#008000;"># Prompt the user for the password    </span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum101"> 101:</span>     $string = read-host <span style="color:#006080;">&quot;Please Enter User Password&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum102"> 102:</span>     <span style="color:#008000;"># Encrypt the string and store it into the $encrypted variable</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum103"> 103:</span>     $encrypted = Encrypt-String $string <span style="color:#006080;">&quot;MyStrongPassword&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum104"> 104:</span>     <span style="color:#008000;"># Write result to the screen</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum105"> 105:</span>     write-host <span style="color:#006080;">&quot;Encrypted Password is: $encrypted&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum106"> 106:</span>     write-host <span style="color:#006080;">&quot;&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum107"> 107:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum108"> 108:</span>     write-host <span style="color:#006080;">&quot;Testing Decryption of Password...&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum109"> 109:</span>     </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum110"> 110:</span>     <span style="color:#008000;"># Decrypts the string and stores the decrypted value in $decrypted</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum111"> 111:</span>     $decrypted = Decrypt-String $encrypted <span style="color:#006080;">&quot;MyStrongPassword&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum112"> 112:</span>     <span style="color:#008000;"># Writes the decrpted value to the screen</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum113"> 113:</span>     write-host <span style="color:#006080;">&quot;Decrypted Password is: $decrypted&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum114"> 114:</span>     write-host <span style="color:#006080;">&quot;&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum115"> 115:</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum116"> 116:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum117"> 117:</span> <span style="color:#0000ff;">while</span> ($me <span style="color:#cc6633;">-ne</span> 1)</pre>
<p><!--CRLF--></div>
</div>
<p><strong>To use this Function: </strong></p>
<p><strong>Start</strong> &gt; <strong>Run </strong>&gt; Type <strong>powershell.exe –noexit c:\location\EncryptDecryptString.ps1</strong> </p>
<p><strong>** When you are done close the window.</strong></p>
<h2>Function for Encrypting Username and Passwords in PowerShell</h2>
<p><strong><a href="http://www.brentblawat.com/blog/codesnippets/EncryptDecryptStringUP.PS1" target="_blank">Download PS1 Here</a></strong></p>
<p>You will notice that I changed the Passphrase for both the username and the password. This is not necessary, however, it adds another layer of security. Try not to encrypt everything with the same passphrase. If one item gets compromised, everything encrypted under that passphrase is compromised.</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;height:2019px;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#008000;">#################</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> <span style="color:#008000;"># Powershell Allows The Loading of .NET Assemblies</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span> <span style="color:#008000;"># Load the Security assembly to use with this script </span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum4">   4:</span> <span style="color:#008000;">#################</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum5">   5:</span> [Reflection.Assembly]::LoadWithPartialName(<span style="color:#006080;">&quot;System.Security&quot;</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum6">   6:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum7">   7:</span> <span style="color:#008000;">#################</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum8">   8:</span> <span style="color:#008000;"># This function is to Encrypt A String.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum9">   9:</span> <span style="color:#008000;"># $string is the string to encrypt, $passphrase is a second security &quot;password&quot; that has to be passed to decrypt.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum10">  10:</span> <span style="color:#008000;"># $salt is used during the generation of the crypto password to prevent password guessing.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum11">  11:</span> <span style="color:#008000;"># $init is used to compute the crypto hash -- a checksum of the encryption</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum12">  12:</span> <span style="color:#008000;">#################</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum13">  13:</span> <span style="color:#0000ff;">function</span> Encrypt-String($String, $Passphrase, $salt=<span style="color:#006080;">&quot;SaltCrypto&quot;</span>, $init=<span style="color:#006080;">&quot;IV_Password&quot;</span>, [<span style="color:#0000ff;">switch</span>]$arrayOutput)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum14">  14:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum15">  15:</span>     <span style="color:#008000;"># Create a COM Object for RijndaelManaged Cryptography</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum16">  16:</span>     $r = new-Object System.Security.Cryptography.RijndaelManaged</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum17">  17:</span>     <span style="color:#008000;"># Convert the Passphrase to UTF8 Bytes</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum18">  18:</span>     $pass = [Text.Encoding]::UTF8.GetBytes($Passphrase)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum19">  19:</span>     <span style="color:#008000;"># Convert the Salt to UTF Bytes</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum20">  20:</span>     $salt = [Text.Encoding]::UTF8.GetBytes($salt)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum21">  21:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum22">  22:</span>     <span style="color:#008000;"># Create the Encryption Key using the passphrase, salt and SHA1 algorithm at 256 bits</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum23">  23:</span>     $r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, <span style="color:#006080;">&quot;SHA1&quot;</span>, 5).GetBytes(32) <span style="color:#008000;">#256/8</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum24">  24:</span>     <span style="color:#008000;"># Create the Intersecting Vector Cryptology Hash with the init</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum25">  25:</span>     $r.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum26">  26:</span>     </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum27">  27:</span>     <span style="color:#008000;"># Starts the New Encryption using the Key and IV   </span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum28">  28:</span>     $c = $r.CreateEncryptor()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum29">  29:</span>     <span style="color:#008000;"># Creates a MemoryStream to do the encryption in</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum30">  30:</span>     $ms = new-Object IO.MemoryStream</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum31">  31:</span>     <span style="color:#008000;"># Creates the new Cryptology Stream --&gt; Outputs to $MS or Memory Stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum32">  32:</span>     $cs = new-Object Security.Cryptography.CryptoStream $ms,$c,<span style="color:#006080;">&quot;Write&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum33">  33:</span>     <span style="color:#008000;"># Starts the new Cryptology Stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum34">  34:</span>     $sw = new-Object IO.StreamWriter $cs</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum35">  35:</span>     <span style="color:#008000;"># Writes the string in the Cryptology Stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum36">  36:</span>     $sw.Write($String)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum37">  37:</span>     <span style="color:#008000;"># Stops the stream writer</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum38">  38:</span>     $sw.Close()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum39">  39:</span>     <span style="color:#008000;"># Stops the Cryptology Stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum40">  40:</span>     $cs.Close()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum41">  41:</span>     <span style="color:#008000;"># Stops writing to Memory</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum42">  42:</span>     $ms.Close()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum43">  43:</span>     <span style="color:#008000;"># Clears the IV and HASH from memory to prevent memory read attacks</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum44">  44:</span>     $r.Clear()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum45">  45:</span>     <span style="color:#008000;"># Takes the MemoryStream and puts it to an array</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum46">  46:</span>     [byte[]]$result = $ms.ToArray()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum47">  47:</span>     <span style="color:#008000;"># Converts the array from Base 64 to a string and returns</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum48">  48:</span>     <span style="color:#0000ff;">return</span> [Convert]::ToBase64String($result)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum49">  49:</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum50">  50:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum51">  51:</span> <span style="color:#0000ff;">function</span> Decrypt-String($Encrypted, $Passphrase, $salt=<span style="color:#006080;">&quot;SaltCrypto&quot;</span>, $init=<span style="color:#006080;">&quot;IV_Password&quot;</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum52">  52:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum53">  53:</span>     <span style="color:#008000;"># If the value in the Encrypted is a string, convert it to Base64</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum54">  54:</span>     <span style="color:#0000ff;">if</span>($Encrypted <span style="color:#cc6633;">-is</span> [string]){</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum55">  55:</span>         $Encrypted = [Convert]::FromBase64String($Encrypted)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum56">  56:</span>        }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum57">  57:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum58">  58:</span>     <span style="color:#008000;"># Create a COM Object for RijndaelManaged Cryptography</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum59">  59:</span>     $r = new-Object System.Security.Cryptography.RijndaelManaged</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum60">  60:</span>     <span style="color:#008000;"># Convert the Passphrase to UTF8 Bytes</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum61">  61:</span>     $pass = [Text.Encoding]::UTF8.GetBytes($Passphrase)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum62">  62:</span>     <span style="color:#008000;"># Convert the Salt to UTF Bytes</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum63">  63:</span>     $salt = [Text.Encoding]::UTF8.GetBytes($salt)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum64">  64:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum65">  65:</span>     <span style="color:#008000;"># Create the Encryption Key using the passphrase, salt and SHA1 algorithm at 256 bits</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum66">  66:</span>     $r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, <span style="color:#006080;">&quot;SHA1&quot;</span>, 5).GetBytes(32) <span style="color:#008000;">#256/8</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum67">  67:</span>     <span style="color:#008000;"># Create the Intersecting Vector Cryptology Hash with the init</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum68">  68:</span>     $r.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum69">  69:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum70">  70:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum71">  71:</span>     <span style="color:#008000;"># Create a new Decryptor</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum72">  72:</span>     $d = $r.CreateDecryptor()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum73">  73:</span>     <span style="color:#008000;"># Create a New memory stream with the encrypted value.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum74">  74:</span>     $ms = new-Object IO.MemoryStream @(,$Encrypted)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum75">  75:</span>     <span style="color:#008000;"># Read the new memory stream and read it in the cryptology stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum76">  76:</span>     $cs = new-Object Security.Cryptography.CryptoStream $ms,$d,<span style="color:#006080;">&quot;Read&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum77">  77:</span>     <span style="color:#008000;"># Read the new decrypted stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum78">  78:</span>     $sr = new-Object IO.StreamReader $cs</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum79">  79:</span>     <span style="color:#008000;"># Return from the function the stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum80">  80:</span>     Write-Output $sr.ReadToEnd()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum81">  81:</span>     <span style="color:#008000;"># Stops the stream    </span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum82">  82:</span>     $sr.Close()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum83">  83:</span>     <span style="color:#008000;"># Stops the crypology stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum84">  84:</span>     $cs.Close()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum85">  85:</span>     <span style="color:#008000;"># Stops the memory stream</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum86">  86:</span>     $ms.Close()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum87">  87:</span>     <span style="color:#008000;"># Clears the RijndaelManaged Cryptology IV and Key</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum88">  88:</span>     $r.Clear()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum89">  89:</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum90">  90:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum91">  91:</span> <span style="color:#008000;"># This clears the screen of the output from the loading of the assembly.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum92">  92:</span> cls</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum93">  93:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum94">  94:</span> <span style="color:#008000;"># $me will never = 1, so It will run indefinately</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum95">  95:</span> $me = 0</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum96">  96:</span>     write-host <span style="color:#006080;">&quot;To End This Application, Close the Window&quot;</span>    </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum97">  97:</span>     Write-host <span style="color:#006080;">&quot;&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum98">  98:</span> do</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum99">  99:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum100"> 100:</span>     <span style="color:#008000;"># Prompt the user for the password    </span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum101"> 101:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum102"> 102:</span>     $ustring = read-host <span style="color:#006080;">&quot;(Case Sensitive) Please Enter Username&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum103"> 103:</span>     $pstring = read-host <span style="color:#006080;">&quot;(Case Sensitive) Please Enter User Password&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum104"> 104:</span>     <span style="color:#008000;"># Encrypt the string and store it into the $encrypted variable</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum105"> 105:</span>     $uencrypted = Encrypt-String $ustring <span style="color:#006080;">&quot;U_MyStrongPassword&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum106"> 106:</span>     $pencrypted = Encrypt-String $pstring <span style="color:#006080;">&quot;P_MyStrongPassword&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum107"> 107:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum108"> 108:</span>     <span style="color:#008000;"># Write result to the screen</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum109"> 109:</span>     write-host <span style="color:#006080;">&quot;Encrypted Username is: $uencrypted&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum110"> 110:</span>     write-host <span style="color:#006080;">&quot;&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum111"> 111:</span>     write-host <span style="color:#006080;">&quot;Encrypted Password is: $pencrypted&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum112"> 112:</span>     write-host <span style="color:#006080;">&quot;&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum113"> 113:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum114"> 114:</span>     write-host <span style="color:#006080;">&quot;Testing Decryption of Username / Password...&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum115"> 115:</span>     write-host <span style="color:#006080;">&quot;&quot;</span>    </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum116"> 116:</span>     <span style="color:#008000;"># Decrypts the string and stores the decrypted value in $decrypted</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum117"> 117:</span>     $udecrypted = Decrypt-String $uencrypted <span style="color:#006080;">&quot;U_MyStrongPassword&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum118"> 118:</span>     $pdecrypted = Decrypt-String $pencrypted <span style="color:#006080;">&quot;P_MyStrongPassword&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum119"> 119:</span>     </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum120"> 120:</span>     <span style="color:#008000;"># Writes the decrpted value to the screen</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum121"> 121:</span>     write-host <span style="color:#006080;">&quot;Decrypted Password is: $udecrypted&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum122"> 122:</span>     write-host <span style="color:#006080;">&quot;&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum123"> 123:</span>     write-host <span style="color:#006080;">&quot;Decrypted Password is: $pdecrypted&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum124"> 124:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum125"> 125:</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum126"> 126:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum127"> 127:</span> <span style="color:#0000ff;">while</span> ($me <span style="color:#cc6633;">-ne</span> 1)</pre>
<p><!--CRLF--></div>
</div>
<p><strong>To use this Function: </strong></p>
<p><strong>Start</strong> &gt; <strong>Run </strong>&gt; Type <strong>powershell.exe –noexit c:\location\EncryptDecryptStringUP.ps1</strong> </p>
<p><strong>** When you are done close the window.</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentblawat.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentblawat.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brentblawat.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brentblawat.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brentblawat.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brentblawat.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brentblawat.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brentblawat.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brentblawat.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brentblawat.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brentblawat.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brentblawat.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brentblawat.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brentblawat.wordpress.com/468/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=468&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittangents.com/2010/03/20/powershell-script-encrypting-decrypting-a-string-function-encrypt-string/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fd28fc9e2db7e469f8237a6d55fba2b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentblawat</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell Script: Finding A Distinguished Name of a Group/User: Function Find-DN</title>
		<link>http://bittangents.com/2010/03/08/powershell-script-finding-a-distinguished-name-of-a-groupuser-function-find-dn/</link>
		<comments>http://bittangents.com/2010/03/08/powershell-script-finding-a-distinguished-name-of-a-groupuser-function-find-dn/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 22:18:43 +0000</pubDate>
		<dc:creator>brentblawat</dc:creator>
				<category><![CDATA[Powershell Tangents]]></category>

		<guid isPermaLink="false">http://brentblawat.wordpress.com/2010/03/08/powershell-script-finding-a-distinguished-name-of-a-groupuser-function-find-dn/</guid>
		<description><![CDATA[By: Brenton Blawat This article explains the the method by which one would be able to Search Active Directory for the distinguished name of a User or Group. This is helpful when trying to add an object to Active Directory or adding Users to Groups. Function Find-DN Finding Distinguished Name: Download PS1 Here 1: # [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=465&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>By: Brenton Blawat</strong></p>
<p>This article explains the the method by which one would be able to Search Active Directory for the distinguished name of a User or Group. This is helpful when trying to add an object to Active Directory or adding Users to Groups.</p>
<p><strong>Function Find-DN Finding Distinguished Name:</strong> <a href="http://www.brentblawat.com/blog/codesnippets/find-dn.ps1"><strong>Download PS1 Here</strong></a></p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#008000;"># Function Find Distinguished Name</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> <span style="color:#0000ff;">function</span> find-dn { <span style="color:#0000ff;">param</span>([string]$adfindtype, [string]$cName)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span>     <span style="color:#008000;"># Create A New ADSI Call</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum4">   4:</span>     $root = [ADSI]<span style="color:#006080;">''</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum5">   5:</span>     <span style="color:#008000;"># Create a New DirectorySearcher Object</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum6">   6:</span>     $searcher = new-object System.DirectoryServices.DirectorySearcher($root)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum7">   7:</span>     <span style="color:#008000;"># Set the filter to search for a specific CNAME</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum8">   8:</span>     $searcher.<span style="color:#0000ff;">filter</span> = <span style="color:#006080;">&quot;(&amp;(objectClass=$adfindtype) (CN=$cName))&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum9">   9:</span>     <span style="color:#008000;"># Set results in $adfind variable</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum10">  10:</span>     $adfind = $searcher.findall()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum11">  11:</span>     </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum12">  12:</span>     <span style="color:#008000;"># If Search has Multiple Answers </span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum13">  13:</span>     <span style="color:#0000ff;">if</span> ($adfind.count <span style="color:#cc6633;">-gt</span> 1) {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum14">  14:</span>         $count = 0 </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum15">  15:</span>         <span style="color:#0000ff;">foreach</span>($i <span style="color:#0000ff;">in</span> $adfind)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum16">  16:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum17">  17:</span>             <span style="color:#008000;"># Write Answers On Screen</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum18">  18:</span>             write-host $count <span style="color:#006080;">&quot;: &quot;</span> $i.path</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum19">  19:</span>             $count += 1</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum20">  20:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum21">  21:</span>         <span style="color:#008000;"># Prompt User For Selection</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum22">  22:</span>         $selection = Read-Host <span style="color:#006080;">&quot;Please select item: &quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum23">  23:</span>         <span style="color:#008000;"># Return the Selection</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum24">  24:</span>         <span style="color:#0000ff;">return</span> $adfind[$selection].path</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum25">  25:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum26">  26:</span>     <span style="color:#008000;"># Return The Answer</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum27">  27:</span>     <span style="color:#0000ff;">return</span> $adfind[0].path</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum28">  28:</span> }</pre>
<p><!--CRLF--></div>
</div>
<p><strong>Using this Function:</strong></p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#008000;"># To use the function to find a User:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> find-dn <span style="color:#006080;">&quot;user&quot;</span> <span style="color:#006080;">&quot;Blawat&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum4">   4:</span> <span style="color:#008000;"># To use the function to find a Group:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum5">   5:</span> find-dn <span style="color:#006080;">&quot;group&quot;</span> <span style="color:#006080;">&quot;IT Help Desk&quot;</span></pre>
<p><!--CRLF--></div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentblawat.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentblawat.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brentblawat.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brentblawat.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brentblawat.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brentblawat.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brentblawat.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brentblawat.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brentblawat.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brentblawat.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brentblawat.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brentblawat.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brentblawat.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brentblawat.wordpress.com/465/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=465&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittangents.com/2010/03/08/powershell-script-finding-a-distinguished-name-of-a-groupuser-function-find-dn/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fd28fc9e2db7e469f8237a6d55fba2b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentblawat</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell Script: Retrieving Distinguished name (DN) from A Fully Qualified Domain Name (FQDN)</title>
		<link>http://bittangents.com/2010/02/22/powershell-script-retrieving-distinguished-name-dn-from-a-fully-qualified-domain-name-fqdn/</link>
		<comments>http://bittangents.com/2010/02/22/powershell-script-retrieving-distinguished-name-dn-from-a-fully-qualified-domain-name-fqdn/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 19:49:40 +0000</pubDate>
		<dc:creator>brentblawat</dc:creator>
				<category><![CDATA[Powershell Tangents]]></category>

		<guid isPermaLink="false">http://brentblawat.wordpress.com/2010/02/22/powershell-script-retrieving-distinguished-name-dn-from-a-fully-qualified-domain-name-fqdn/</guid>
		<description><![CDATA[By: Brenton Blawat While there are many posts that describe the code to do this function, there aren’t many posts that provide variables with meaning or actually describe the syntax. This post describes the method by which you can retrieve a Distinguished Name from a Fully Qualified Domain Name. Quick Reference: Fully Qualified Domain Name [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=444&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>By: Brenton Blawat</strong></p>
<p>While there are many posts that describe the code to do this function, there aren’t many posts that provide variables with meaning or actually describe the syntax. This post describes the method by which you can retrieve a Distinguished Name from a Fully Qualified Domain Name. </p>
<p><u>Quick Reference:</u> </p>
<p>Fully Qualified Domain Name (FQDN): division.domain.root</p>
<p>Distinguished Name (DC): DC=division,DC=Domain,DC=root</p>
<p>Canonical Name(CN): division.domain.root/OrganizationalUnit/</p>
<p>If you are looking for a quick way to obtain a Distinguished Name or Fully Qualified Domain Name <a href="http://brentblawat.wordpress.com/2010/02/22/powershell-script-distinguished-name-fully-qualified-domain-name-to-string/">See this article.</a></p>
<p>&#160;</p>
<h2>Mr. Weaver’s Code</h2>
<p>Mark A. Weaver’s post <a href="http://vmweaver.com/index.php/2009/08/powershell-recursive-group-membership/">Powershell – Recursive Group Membership</a>, he describes the methods by which you can convert to and from multiple variables. Here is how Mr. Weaver performs the conversion operation:</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.86%;font-family:&#39;direction:ltr;height:210px;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#0000ff;">function</span> Convert-DNStoDN ($DNSName)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span>    <span style="color:#008000;">#  Create an array of each item in the string separated by &quot;.&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum4">   4:</span>    $DNSArray = $DNSName.Split(<span style="color:#006080;">&quot;.&quot;</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum5">   5:</span>   <span style="color:#008000;"># Let's go through our new array and do something with each item</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum6">   6:</span>    <span style="color:#0000ff;">for</span> ($x = 0; $x <span style="color:#cc6633;">-lt</span> $DNSArray.Length ; $x++)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum7">   7:</span>       {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum8">   8:</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></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum9">   9:</span>         <span style="color:#008000;"># $Separator equal to nothing.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum10">  10:</span>         <span style="color:#008000;"># Remember that we need to go to Length-1 because arrays are &quot;0 based indexes&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum11">  11:</span>          <span style="color:#0000ff;">if</span> ($x <span style="color:#cc6633;">-eq</span> ($DNSArray.Length - 1)){$Separator = <span style="color:#006080;">&quot;&quot;</span>}<span style="color:#0000ff;">else</span>{$Separator =<span style="color:#006080;">&quot;,&quot;</span>}</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum12">  12:</span>          [string]$DN += <span style="color:#006080;">&quot;DC=&quot;</span> + $DNSArray[$x] + $Separator</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum13">  13:</span>       }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum14">  14:</span>    <span style="color:#0000ff;">return</span> $DN</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum15">  15:</span> }</pre>
<p><!--CRLF--></div>
</div>
<h2>My Code &#8211; Explained</h2>
<p>While my code is almost identical to Mr. Weaver’s Code, my only criticism is not providing useful variables and describing the functions. I can state, however, Mr. Weaver’s code provided a platform for a function that I use in a large production environment. I took the liberty to optimize the code (slightly) to meet my needs (Thank you sir!).</p>
<p><strong>My Function looks like: <a href="http://www.brentblawat.com/blog/codesnippets/FQDN_DN.PS1">Download PS1 Here</a></strong></p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;height:172px;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#0000ff;">function</span> Get-Domain {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span>     </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span>     <span style="color:#008000;">#Retrieve the Fully Qualified Domain Name if one is not supplied</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum4">   4:</span>     <span style="color:#008000;"># division.domain.root</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum5">   5:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum6">   6:</span>     <span style="color:#0000ff;">if</span> ($FQDN <span style="color:#cc6633;">-eq</span> <span style="color:#006080;">&quot;&quot;</span>) {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum7">   7:</span>         [String]$fqdn = [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum8">   8:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum9">   9:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum10">  10:</span>     <span style="color:#008000;"># Create a New Array 'Item' for each item in between the '.' characters</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum11">  11:</span>     <span style="color:#008000;"># Arrayitem1 division</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum12">  12:</span>     <span style="color:#008000;"># Arrayitem2 domain</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum13">  13:</span>     <span style="color:#008000;"># Arrayitem3 root</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum14">  14:</span>     $FQDNArray = $FQDN.split(<span style="color:#006080;">&quot;.&quot;</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum15">  15:</span>     </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum16">  16:</span>     <span style="color:#008000;"># Add A Separator of ','</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum17">  17:</span>     $Separator = <span style="color:#006080;">&quot;,&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum18">  18:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum19">  19:</span>     <span style="color:#008000;"># For Each Item in the Array</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum20">  20:</span>     <span style="color:#008000;"># for (CreateVar; Condition; RepeatAction)</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum21">  21:</span>     <span style="color:#008000;"># for ($x is now equal to 0; while $x is less than total array length; add 1 to X</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum22">  22:</span>     <span style="color:#0000ff;">for</span> ($x = 0; $x <span style="color:#cc6633;">-lt</span> $FQDNArray.Length ; $x++)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum23">  23:</span>         { </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum24">  24:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum25">  25:</span>         <span style="color:#008000;">#If it's the last item in the array don't append a ','</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum26">  26:</span>         <span style="color:#0000ff;">if</span> ($x <span style="color:#cc6633;">-eq</span> ($FQDNArray.Length - 1)) { $Separator = <span style="color:#006080;">&quot;&quot;</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum27">  27:</span>         </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum28">  28:</span>         <span style="color:#008000;"># Append to $DN DC= plus the array item with a separator after</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum29">  29:</span>         [string]$DN += <span style="color:#006080;">&quot;DC=&quot;</span> + $FQDNArray[$x] + $Separator</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum30">  30:</span>         </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum31">  31:</span>         <span style="color:#008000;"># continue to next item in the array</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum32">  32:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum33">  33:</span>     </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum34">  34:</span>     <span style="color:#008000;">#return the Distinguished Name</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum35">  35:</span>     <span style="color:#0000ff;">return</span> $DN</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum36">  36:</span> }</pre>
<p><!--CRLF--></div>
</div>
<p><strong>To use the Function </strong>to get the Distinguished Name of the Domain:</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.33%;font-family:&#39;direction:ltr;height:39px;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#008000;"># Store the distinguished name in a variable named $objCrntDN.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> $objCrntDN = Get-Domain</pre>
<p><!--CRLF--></div>
</div>
<p><strong>To use the function </strong>to get the Distinguished Name From a Fully Qualified Domain Name:</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.1%;font-family:&#39;direction:ltr;height:79px;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#008000;"># Store the distinguished name in a variable named $objCrntDN</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> <span style="color:#008000;"># Pass the Fully Qualified Domain Name with call</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span> $objCrntDN = Get-Domain division.domain.root </pre>
<p><!--CRLF--></div>
</div>
<p><strong>Note: </strong>This function also works if you place the division.domain.root in parentheses with quotations:</p>
<p><strong>Get-Domain(“division.domain.root”)</strong></p>
<h2>&#160;</h2>
<h2>What’s Different??</h2>
<p>While the output is basically the same, I’ve made a few changes in the code:</p>
<ol>
<li>“DNSname” is technically inaccurate, while I understand what he is meaning. He is referring to is the FQDN – a point of confusion for the readers. </li>
<li>I made the passing of a FQDN (optional) – as sometimes we don’t need to determine the FQDN (outside the function) before we get the Distinguished Name. </li>
<li>I named my function ‘Get-Domain’ . DNS-DN is a very specific function. Your will see that Marc has to call three different functions to convert between each of these. I chose to make a single function, and establish what the ultimate output will be. Name the function what you are getting or creating with the function. Get-Domain –&gt; You already know what the output will be &#8212; the Domain. </li>
<li>I removed the <em>Else { $separator }</em> out of the loop. In batch processing such as PowerShell, the interpreter will replace the $separator variable each time it passes through the loop for the items in the array. To make the code more efficient, I set the variable outside the loop as it only gets changed for the last array evaluation.</li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentblawat.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentblawat.wordpress.com/444/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brentblawat.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brentblawat.wordpress.com/444/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brentblawat.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brentblawat.wordpress.com/444/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brentblawat.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brentblawat.wordpress.com/444/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brentblawat.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brentblawat.wordpress.com/444/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brentblawat.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brentblawat.wordpress.com/444/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brentblawat.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brentblawat.wordpress.com/444/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=444&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittangents.com/2010/02/22/powershell-script-retrieving-distinguished-name-dn-from-a-fully-qualified-domain-name-fqdn/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fd28fc9e2db7e469f8237a6d55fba2b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentblawat</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell Script: Distinguished Name / Fully Qualified Domain Name to string</title>
		<link>http://bittangents.com/2010/02/22/powershell-script-distinguished-name-fully-qualified-domain-name-to-string/</link>
		<comments>http://bittangents.com/2010/02/22/powershell-script-distinguished-name-fully-qualified-domain-name-to-string/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 19:39:24 +0000</pubDate>
		<dc:creator>brentblawat</dc:creator>
				<category><![CDATA[Powershell Tangents]]></category>

		<guid isPermaLink="false">http://brentblawat.wordpress.com/2010/02/22/powershell-script-distinguished-name-fully-qualified-domain-name-to-string/</guid>
		<description><![CDATA[By: Brenton Blawat This article is designed to be short and sweet. This article displays the method by which one would retrieve the FQDN or Distinguished Name of the Domain. This is code is very useful for any operations in Active Directory. A must know for any scripter that needs to call the domain on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=443&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[</p>
<p><strong>By: Brenton Blawat</strong></p>
<p>This article is designed to be short and sweet. This article displays the method by which one would retrieve the FQDN or Distinguished Name of the Domain. This is code is very useful for any operations in Active Directory. A must know for any scripter that needs to call the domain on a system without hard coding the value in the script.</p>
<p>Lets take a theoretical network that consists of ‘division’ subdomain, ‘domain’ as the domain, and ‘root’ as the domain root.</p>
<h2>Root Distinguished name &#8211; Easy Method in PowerShell</h2>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;height:68px;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#008000;"># Instantiate The ADSI Provider</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> $root = [ADSI]<span style="color:#006080;">''</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span> $CurrentDN = $root.DistinguishedName</pre>
<p><!--CRLF--></div>
</div>
<p><strong>Result:</strong> </p>
<p>The variable $CurrentDN will contain:</p>
<p>DN=division,DN=domain,DN=root</p>
<p>E.G. DN=bittangents,DN=com</p>
<h2>Root Fully Qualified Domain Name (FQDN) – Easy Method In PowerShell</h2>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;height:67px;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#008000;"># Retrieve the Fully Qualified Domain Name and store it in $FQDN Variable</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> [String]$FQDN =  [System.DirectoryServices.ActiveDirectory.Domain]::getCurrentDomain()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span>&#160; </pre>
<p><!--CRLF--></div>
</div>
<p><strong>Result:</strong> </p>
<p>The variable $FQDN will contain:</p>
<p>division.domain.root</p>
<p>E.G. bittangents.com</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentblawat.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentblawat.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brentblawat.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brentblawat.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brentblawat.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brentblawat.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brentblawat.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brentblawat.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brentblawat.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brentblawat.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brentblawat.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brentblawat.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brentblawat.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brentblawat.wordpress.com/443/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittangents.com&#038;blog=4066351&#038;post=443&#038;subd=brentblawat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittangents.com/2010/02/22/powershell-script-distinguished-name-fully-qualified-domain-name-to-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fd28fc9e2db7e469f8237a6d55fba2b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentblawat</media:title>
		</media:content>
	</item>
	</channel>
</rss>
