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

<channel>
	<title>Jeff Wouters&#039;s Blog</title>
	<atom:link href="http://jeffwouters.nl/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://jeffwouters.nl</link>
	<description>A geeky mind is a joy forever...</description>
	<lastBuildDate>Fri, 18 May 2012 11:36:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>PowerShell &#8211; Searching for the cause of a user account that keeps getting locked out</title>
		<link>http://jeffwouters.nl/index.php/2012/05/powershell-searching-for-the-cause-of-a-user-account-that-keeps-getting-locked-out/</link>
		<comments>http://jeffwouters.nl/index.php/2012/05/powershell-searching-for-the-cause-of-a-user-account-that-keeps-getting-locked-out/#comments</comments>
		<pubDate>Fri, 18 May 2012 11:36:28 +0000</pubDate>
		<dc:creator>Jeff Wouters</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://jeffwouters.nl/?p=1004</guid>
		<description><![CDATA[Earlier this week a colleague was asked to troubleshoot an issue where a user account kept getting locked out. So, we wanted to know from which device the faulty credentials were being used that were causing this (perhaps some crappy application which was using ‘old’ credentials? we didn’t knew…). So, with the following PowerShell ‘oneliner’ [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fpowershell-searching-for-the-cause-of-a-user-account-that-keeps-getting-locked-out%2F' data-shr_title='PowerShell+-+Searching+for+the+cause+of+a+user+account+that+keeps+getting+locked+out'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fpowershell-searching-for-the-cause-of-a-user-account-that-keeps-getting-locked-out%2F' data-shr_title='PowerShell+-+Searching+for+the+cause+of+a+user+account+that+keeps+getting+locked+out'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p><font size="3" face="Arial">Earlier this week a colleague was asked to troubleshoot an issue where a user account kept getting locked out. So, we wanted to know from which device the faulty credentials were being used that were causing this (perhaps some crappy application which was using ‘old’ credentials? we didn’t knew…).</font></p>
<p><font size="3" face="Arial">So, with the following PowerShell ‘oneliner’ you can quickly search through the eventlog of a domain controller for the event which describes the faulty logon attempt (or attempts):</font></p>
<blockquote><p><font size="3" face="Arial">Get-EventLog -ComputerName DC01 &quot;Security&quot; -InstanceID &quot;4740&quot; -Message *&quot;USERNAME&quot;*</font></p>
</blockquote>
<p><font size="3" face="Arial">This will give you a bunch of information per event it has found, so to filter it so it will only show the message and the time the event was generated:</font></p>
<blockquote><p><font size="3" face="Arial">Get-Eventlog -ComputerName DC01 &quot;Security&quot; -InstanceID &quot;4740&quot; -Message *&quot;USERNAME&quot;* | Format-List Timegenerated, Message</font></p>
</blockquote>
<p><font size="3" face="Arial">But perhaps you’ve got multiple domain controllers that you want to search through?</font></p>
<blockquote><p><font size="3" face="Arial">Get-Eventlog –ComputerName ([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).FindDomainController() &quot;Security&quot; -InstanceID &quot;4740&quot; -Message *&quot;USERNAME&quot;* | Format-List Timegenerated, Message</font></p>
</blockquote>
<div class="shr-publisher-1004"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=PowerShell+%E2%80%93+Searching+for+the+cause+of+a+user+account+that+keeps+getting+locked+out+http%3A%2F%2Fjeffwouters.nl%2F%3Fp%3D1004" title="Post to Twitter"><img class="nothumb" src="http://jeffwouters.nl/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://jeffwouters.nl/index.php/2012/05/powershell-searching-for-the-cause-of-a-user-account-that-keeps-getting-locked-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert a domain name to a usable distinguished name format</title>
		<link>http://jeffwouters.nl/index.php/2012/05/convert-a-domain-name-to-a-usable-distinguished-name-format/</link>
		<comments>http://jeffwouters.nl/index.php/2012/05/convert-a-domain-name-to-a-usable-distinguished-name-format/#comments</comments>
		<pubDate>Tue, 15 May 2012 06:59:23 +0000</pubDate>
		<dc:creator>Jeff Wouters</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://jeffwouters.nl/?p=997</guid>
		<description><![CDATA[Every once in a while I need to get the domain name from a computer and use it in a PowerShell script. But when you do something like “Get-WMIObject –Class Win32_ComputerSystem &#124; Select-Object –ExpandProperty Domain” you’ll get an output such as “jeffwouters.lan”. But most of the times, a script will require an input like “DC=jeffwouters,DC=lan” [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fconvert-a-domain-name-to-a-usable-distinguished-name-format%2F' data-shr_title='Convert+a+domain+name+to+a+usable+distinguished+name+format'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fconvert-a-domain-name-to-a-usable-distinguished-name-format%2F' data-shr_title='Convert+a+domain+name+to+a+usable+distinguished+name+format'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p><span style="font-family: Arial; font-size: small;">Every once in a while I need to get the domain name from a computer and use it in a PowerShell script. But when you do something like “<em>Get-WMIObject –Class Win32_ComputerSystem | Select-Object –ExpandProperty Domain</em>” you’ll get an output such as “<em>jeffwouters.lan</em>”.<br />
But most of the times, a script will require an input like “DC=jeffwouters,DC=lan” <img class="wlEmoticon wlEmoticon-sadsmile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-sadsmile1.png" alt="Bedroefde emoticon" /></span></p>
<p><span style="font-family: Arial; font-size: small;">Now let’s say that we have a given variable:</span></p>
<blockquote><p><span style="font-family: Arial; font-size: small;">$DomainName = “jeffwouters.lan”</span></p></blockquote>
<p><span style="font-family: Arial; font-size: small;">By using the “split” method, you can split a string into separate values:</span></p>
<blockquote><p><span style="font-family: Arial; font-size: small;">$DomainSplit = $DomainName.split(&#8220;.&#8221;)</span></p></blockquote>
<p><span style="font-family: Arial; font-size: small;">This will give you a value “<em>jeffwouters</em>” and a value “<em>lan</em>” instead of the given value “<em>jeffwouters.lan</em>”.</span></p>
<p><span style="font-family: Arial; font-size: small;">Next, we would want to put something in front of the values, namely the “<em>DC=</em>” characters.<br />
This can be done easily, just by creating a new variable with something like “DC=$(DomainSplit)”… but this will provide you with a nasty.<br />
Why? Because there are multiple values in the variable (it has become an array <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-winkingsmile4.png" alt="Knipogende emoticon" />). The correct way to select the separate values is to add [0] or [1] after the variable where the number specifies the character.<br />
Ow, and not to forget… between both values you will need to add a “,” since that’s the correct format for a distinguished name <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-winkingsmile4.png" alt="Knipogende emoticon" /><br />
So, to get the format you desire, the following command will do the trick:</span></p>
<blockquote><p><span style="font-family: Arial; font-size: small;">$DomainName = &#8220;DC=$($DomainSplit[0]),DC=$($DomainSplit[1])&#8221;</span></p></blockquote>
<p><span style="font-family: Arial; font-size: small;">This way, you’ve just converted “jeffwouters.lan” to “DC=jeffwouters,DC=lan” <img class="wlEmoticon wlEmoticon-openmouthedsmile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-openmouthedsmile1.png" alt="Emoticon met brede lach" /></span></p>
<p><span style="font-family: Arial; font-size: small;">Now, there is also a possibility that you have a child domain… something like “test.jeffwouters.lan”. You can convert this the same way as before, simply by adding another “DC=$($DomainSplit[2])”.<br />
And to create a function out of this (since I like re-usable code…):</span></p>
<blockquote><p><span style="font-family: Arial; font-size: small;">Function Convert-ToDistinguishedName()<br />
{<br />
&lt;#<br />
.Synopsis<br />
Function to convert a domain name into a distinguished name format.</span></p>
<p><span style="font-family: Arial; font-size: small;">  .Description<br />
Function to convert a domain name into a distinguished name format.<br />
No default is used.</span></p>
<p><span style="font-family: Arial; font-size: small;">  .Example<br />
Convert-ToDistinguishedName -DomainName &#8220;jeffwouters.lan&#8221;</span></p>
<p><span style="font-family: Arial; font-size: small;">  .Example<br />
Convert-ToDistinguishedName -Name &#8220;jeffwouters.lan&#8221;</span></p>
<p><span style="font-family: Arial; font-size: small;">  .Notes<br />
Author: Jeff Wouters | Methos IT<br />
#&gt;<br />
param ( [Parameter(Position=0, Mandatory=$True)][ValidateNotNullOrEmpty()][Alias('Name')][String]$DomainName )<br />
$DomainSplit = $DomainName.split(&#8220;.&#8221;)<br />
if ($DomainSplit[2] -ne $null) {<br />
$DomainName = &#8220;DC=$($DomainSplit[0]),DC=$($DomainSplit[1]),DC=$($DomainSplit[2])&#8221;<br />
$DomainName<br />
} else {<br />
$DomainName = &#8220;DC=$($DomainSplit[0]),DC=$($DomainSplit[1])&#8221;<br />
$DomainName<br />
}<br />
}</span></p></blockquote>
<p><span style="font-family: Arial; font-size: small;">Now, this is a part of a larger deployment script I’m working on which I  will be posting parts of during the coming weeks.<br />
After the script is finished, I’ll post it in the Microsoft Script Library and on this blog <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-smile2.png" alt="Glimlach" /></span></p>
<div class="shr-publisher-997"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Convert+a+domain+name+to+a+usable+distinguished+name+format+http%3A%2F%2Fjeffwouters.nl%2F%3Fp%3D997" title="Post to Twitter"><img class="nothumb" src="http://jeffwouters.nl/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://jeffwouters.nl/index.php/2012/05/convert-a-domain-name-to-a-usable-distinguished-name-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell &#8211; Create directories and files for demonstrations</title>
		<link>http://jeffwouters.nl/index.php/2012/05/powershell-create-directories-and-files-for-demonstrations/</link>
		<comments>http://jeffwouters.nl/index.php/2012/05/powershell-create-directories-and-files-for-demonstrations/#comments</comments>
		<pubDate>Wed, 09 May 2012 09:16:29 +0000</pubDate>
		<dc:creator>Jeff Wouters</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://jeffwouters.nl/?p=990</guid>
		<description><![CDATA[Sometimes, when I demonstrate the ease and strength of PowerShell to a customer, I need to quickly generate some fake files en directory structure… also those files have to be from different sizes. For this, I’ve created the following script: function New-DemoData ($Path) { &#160; # Usage: New-DemoData “D:\Company” &#160; Push-Location &#160; 1..10 &#124; % [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fpowershell-create-directories-and-files-for-demonstrations%2F' data-shr_title='PowerShell+%26ndash%3B+Create+directories+and+files+for+demonstrations'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fpowershell-create-directories-and-files-for-demonstrations%2F' data-shr_title='PowerShell+%26ndash%3B+Create+directories+and+files+for+demonstrations'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p><font size="3" face="Arial">Sometimes, when I demonstrate the ease and strength of PowerShell to a customer, I need to quickly generate some fake files en directory structure… also those files have to be from different sizes. For this, I’ve created the following script:</font></p>
<blockquote><p><font size="3" face="Arial">function New-DemoData ($Path)       <br />{        <br />&#160; # Usage: New-DemoData “D:\Company”        <br />&#160; Push-Location        <br />&#160; 1..10 | % { Set-Location -Path (New-Item -ItemType directory -path &quot;$path\$_&quot;).fullname -ErrorAction SilentlyContinue        <br />&#160; for ( $i=1; $i -le (Get-Random -Minimum 10 -Maximum 200); $i++ )        <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160; fsutil file createnew (&quot;File&quot; + $i + &quot;.txt&quot;) (Get-Random -Minimum 1024 -Maximum 819200)        <br />&#160;&#160;&#160; }         <br />&#160; }        <br />&#160; Pop-Location        <br />}</font></p>
</blockquote>
<p><font size="3" face="Arial">This script will create 10 folders (named 1-10) at the target path (provided by the parameter) and create a random number of *.txt files (between 10 and 200) in each directory, each file between 1KB and 800KB in size.</font></p>
<div class="shr-publisher-990"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=PowerShell+%E2%80%93+Create+directories+and+files+for+demonstrations+http%3A%2F%2Fjeffwouters.nl%2F%3Fp%3D990" title="Post to Twitter"><img class="nothumb" src="http://jeffwouters.nl/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://jeffwouters.nl/index.php/2012/05/powershell-create-directories-and-files-for-demonstrations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Manage Windows Server 2012 Hyper-V in SCVMM 2012 &#8211;Unknown Hypervisor</title>
		<link>http://jeffwouters.nl/index.php/2012/05/manage-windows-server-2012-hyper-v-in-scvmm-2012-unknown-hypervisor/</link>
		<comments>http://jeffwouters.nl/index.php/2012/05/manage-windows-server-2012-hyper-v-in-scvmm-2012-unknown-hypervisor/#comments</comments>
		<pubDate>Tue, 08 May 2012 07:00:33 +0000</pubDate>
		<dc:creator>Jeff Wouters</dc:creator>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[SCVMM]]></category>

		<guid isPermaLink="false">http://jeffwouters.nl/?p=987</guid>
		<description><![CDATA[This morning I received an email from a community peer stating that he was unable to manage Hyper-V 3.0 in Windows Server 2012 by using SCVMM 2012 CTP. The specific error message: “Error (12704) : Unable to connect to the Hyper-V service on the server &#60;server name&#62;” This is a known issue, but when you [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fmanage-windows-server-2012-hyper-v-in-scvmm-2012-unknown-hypervisor%2F' data-shr_title='Manage+Windows+Server+2012+Hyper-V+in+SCVMM+2012+%26ndash%3BUnknown+Hypervisor'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fmanage-windows-server-2012-hyper-v-in-scvmm-2012-unknown-hypervisor%2F' data-shr_title='Manage+Windows+Server+2012+Hyper-V+in+SCVMM+2012+%26ndash%3BUnknown+Hypervisor'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p><span style="font-family: Arial; font-size: small;">This morning I received an email from a community peer stating that he was unable to manage Hyper-V 3.0 in Windows Server 2012 by using SCVMM 2012 CTP.<br />
The specific error message: “<em>Error (12704) : Unable to connect to the Hyper-V service on the server &lt;server name&gt;</em>”<br />
</span><a href="http://jeffwouters.nl/wp-content/uploads/2012/05/image.png"><span style="font-family: Arial; font-size: small;"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://jeffwouters.nl/wp-content/uploads/2012/05/image_thumb.png" alt="image" width="448" height="176" border="0" /></span></a></p>
<p><span style="font-family: Arial; font-size: small;">This is a known issue, but when you download/install/use the latest release of SCVMM 2012 (it&#8217;s RTM now as far as I know) the problem has been resolved <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-winkingsmile3.png" alt="Knipogende emoticon" /> </span></p>
<p><em>Note: Remember that CTP means Community Technology Preview… in other words: The product isn’t finished yet <img class="wlEmoticon wlEmoticon-hotsmile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-hotsmile2.png" alt="Verhitte emoticon" /></em></p>
<div class="shr-publisher-987"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Manage+Windows+Server+2012+Hyper-V+in+SCVMM+2012+%E2%80%93Unknown+Hypervisor+http%3A%2F%2Fjeffwouters.nl%2F%3Fp%3D987" title="Post to Twitter"><img class="nothumb" src="http://jeffwouters.nl/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://jeffwouters.nl/index.php/2012/05/manage-windows-server-2012-hyper-v-in-scvmm-2012-unknown-hypervisor/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mail enable Active Directory contacts in Exchange with a PowerShell oneliner</title>
		<link>http://jeffwouters.nl/index.php/2012/05/mail-enable-active-directory-contacts-in-exchange-with-a-powershell-oneliner/</link>
		<comments>http://jeffwouters.nl/index.php/2012/05/mail-enable-active-directory-contacts-in-exchange-with-a-powershell-oneliner/#comments</comments>
		<pubDate>Mon, 07 May 2012 12:47:56 +0000</pubDate>
		<dc:creator>Jeff Wouters</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Exchange]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://jeffwouters.nl/?p=980</guid>
		<description><![CDATA[Last week a community peer asked me on Facebook to assist him with a challenge. His issue was that he had imported contacts into Active Directory by using a tool named “ldifde”. This tool also filled in the email address on the contact object in Active Directory. But, he wanted to mail-enable them within Microsoft [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fmail-enable-active-directory-contacts-in-exchange-with-a-powershell-oneliner%2F' data-shr_title='Mail+enable+Active+Directory+contacts+in+Exchange+with+a+PowerShell+oneliner'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fmail-enable-active-directory-contacts-in-exchange-with-a-powershell-oneliner%2F' data-shr_title='Mail+enable+Active+Directory+contacts+in+Exchange+with+a+PowerShell+oneliner'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p><font size="3" face="Arial">Last week a community peer asked me on Facebook to assist him with a challenge.</font></p>
<p><font size="3" face="Arial">His issue was that he had imported contacts into Active Directory by using a tool named “</font><a href="http://support.microsoft.com/kb/237677"><font size="3" face="Arial">ldifde</font></a><font size="3" face="Arial">”. This tool also filled in the email address on the contact object in Active Directory.     <br />But, he wanted to mail-enable them within Microsoft Exchange Server and set the mail address filled in the ‘Email address’ attached to the contact as the external mail address.      <br />Since we’re talking about 2000+&#160; contacts, this is not something you want to do by clicking… so we turned to PowerShell.<img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-openmouthedsmile" alt="Emoticon met brede lach" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-openmouthedsmile.png" /></font></p>
<p><font size="3" face="Arial">And here’s the PowerShell oneliner to do this.</font></p>
<blockquote><p><font size="3" face="Arial">Get-Contact -RecipientTypeDetails Contact -Filter &#8216;WindowsEmailAddress -ne $null&#8217; | foreach { enable-mailcontact -Identity $_ -ExternalEmailAddress $_.WindowsEmailAddress.toS​tring() }</font></p>
</blockquote>
<p><font size="3" face="Arial">Note that this command will search through your entire AD… use the –OrganizationalUnit parameter to search more specific. <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Knipogende emoticon" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-winkingsmile2.png" />      <br />Now, this command took about 15 minutes to run… for about 2300 contacts. A lot better compared to clicking them manually, right? <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-hotsmile" alt="Verhitte emoticon" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-hotsmile1.png" /></font></p>
<p><em><font size="3" face="Arial">Note: Getting an error stating that the “Get-Contact” cmdlet is unknown? Be sure that you’re a member of the “Exchange View-Only Administrators” group!</font></em></p>
<div class="shr-publisher-980"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Mail+enable+Active+Directory+contacts+in+Exchange+with+a+PowerShell+oneliner+http%3A%2F%2Fjeffwouters.nl%2F%3Fp%3D980" title="Post to Twitter"><img class="nothumb" src="http://jeffwouters.nl/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://jeffwouters.nl/index.php/2012/05/mail-enable-active-directory-contacts-in-exchange-with-a-powershell-oneliner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grant full access to a group on a mailbox in Multi-tenant Hosted Exchange environment with a PowerShell oneliner</title>
		<link>http://jeffwouters.nl/index.php/2012/05/grant-full-access-to-a-group-on-a-mailbox-in-multi-tenant-hosted-exchange-environment-with-a-powershell-oneliner/</link>
		<comments>http://jeffwouters.nl/index.php/2012/05/grant-full-access-to-a-group-on-a-mailbox-in-multi-tenant-hosted-exchange-environment-with-a-powershell-oneliner/#comments</comments>
		<pubDate>Thu, 03 May 2012 08:11:18 +0000</pubDate>
		<dc:creator>Jeff Wouters</dc:creator>
				<category><![CDATA[Exchange]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://jeffwouters.nl/?p=958</guid>
		<description><![CDATA[Yesterday I helped a fellow IT Pro out with an issue concerning Exchange and PowerShell. Why user PowerShell? Well, in an Exchange 2010 SP2 Multi-tenant hosted environment there isn’t a management console His goal was to use PowerShell to set full access rights for a group of users on a specific mailbox inside a multi-tenant [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fgrant-full-access-to-a-group-on-a-mailbox-in-multi-tenant-hosted-exchange-environment-with-a-powershell-oneliner%2F' data-shr_title='Grant+full+access+to+a+group+on+a+mailbox+in+Multi-tenant+Hosted+Exchange+environment+with+a+PowerShell+oneliner'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fgrant-full-access-to-a-group-on-a-mailbox-in-multi-tenant-hosted-exchange-environment-with-a-powershell-oneliner%2F' data-shr_title='Grant+full+access+to+a+group+on+a+mailbox+in+Multi-tenant+Hosted+Exchange+environment+with+a+PowerShell+oneliner'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p><font size="3" face="Arial">Yesterday I helped a </font><a href="http://vworld.nl/"><font size="3" face="Arial">fellow IT Pro</font></a><font size="3" face="Arial"> out with an issue concerning Exchange and PowerShell.     <br />Why user PowerShell? Well, in an Exchange 2010 SP2 Multi-tenant hosted environment there isn’t a management console <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Knipogende emoticon" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-winkingsmile1.png" />      <br />His goal was to use PowerShell to set full access rights for a group of users on a specific mailbox inside a multi-tenant environment.      </p>
<p>When you look at the Add-MailboxPermissions cmdlet, you’ll see that there is a <em>–User</em> parameter. But when you would also expect a <em>–Group</em> parameter you will get a little disappointed; there isn’t any <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-sadsmile" alt="Bedroefde emoticon" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-sadsmile.png" /></font></p>
<p><font size="3" face="Arial">All credits go toward the </font><a href="http://twitter.com/vworlddotnl"><font size="3" face="Arial">IT Pro</font></a><font size="3" face="Arial"> I was helping, he found that instead of putting a username after the <em>–User</em> parameter, you can simple put a group name in there and <u>it will work like a charm</u>! <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-hotsmile" alt="Verhitte emoticon" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-hotsmile.png" /></font></p>
<blockquote><p><font size="3" face="Arial">Add-MailboxPermission -Identity &quot;user&quot; -User &quot;groupname&quot; -AccessRights FullAccess -InheritanceType All</font></p>
</blockquote>
<p><font size="3" face="Arial">To me, this just doesn’t sound logical since a user is a user and not a group. So I’m hoping Microsoft will either change the name for the parameter or create a <em>–Group</em> parameter… but that’s for them to decide <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Glimlach" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-smile1.png" /></font></p>
<div class="shr-publisher-958"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Grant+full+access+to+a+group+on+a+mailbox+in+Multi-tenant+Hosted+Exchange+environment+with+a+PowerShell+oneliner+http%3A%2F%2Fjeffwouters.nl%2F%3Fp%3D958" title="Post to Twitter"><img class="nothumb" src="http://jeffwouters.nl/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://jeffwouters.nl/index.php/2012/05/grant-full-access-to-a-group-on-a-mailbox-in-multi-tenant-hosted-exchange-environment-with-a-powershell-oneliner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell function to create a random password with complexity requirement</title>
		<link>http://jeffwouters.nl/index.php/2012/05/powershell-function-to-create-a-random-password-with-complexity-requirement/</link>
		<comments>http://jeffwouters.nl/index.php/2012/05/powershell-function-to-create-a-random-password-with-complexity-requirement/#comments</comments>
		<pubDate>Wed, 02 May 2012 16:52:01 +0000</pubDate>
		<dc:creator>Jeff Wouters</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://jeffwouters.nl/?p=951</guid>
		<description><![CDATA[Today I wrote a post with a Powershell function to create a complex password. Although it does generate a complex password, it would not be enough for the complexity policy for passwords in Windows. This because the script didn’t check if there was a lowercase, uppercase, number and punctuation mark included. Now, until now that [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fpowershell-function-to-create-a-random-password-with-complexity-requirement%2F' data-shr_title='Powershell+function+to+create+a+random+password+with+complexity+requirement'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fpowershell-function-to-create-a-random-password-with-complexity-requirement%2F' data-shr_title='Powershell+function+to+create+a+random+password+with+complexity+requirement'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p><span style="font-family: Arial; font-size: small;">Today I wrote a post with a </span><a href="http://jeffwouters.nl/index.php/2012/05/powershell-function-to-generate-a-random-password/"><span style="font-family: Arial; font-size: small;">Powershell function to create a complex password</span></a><span style="font-family: Arial; font-size: small;">.<br />
Although it does generate a complex password, it would not be enough for the complexity policy for passwords in Windows. This because the script didn’t check if there was a lowercase, uppercase, number and punctuation mark included.</span></p>
<p><span style="font-family: Arial; font-size: small;">Now, until now that script was sufficient for my customers because when you script a password you would not get prompted by a nasty error stating that the provided password does not meet the complexity requirements and stuff like that; it will just ram the password in your user object and be done with it.</span></p>
<p><span style="font-family: Arial; font-size: small;">Now, in the afternoon I received several comments (from <a href="https://twitter.com/#!/pzerger">Pete Zerger</a> amongst others) about this limitation of my function, so (just to make the community peers happy) I re-wrote the function. And since I was at it, now a default length of 8 characters is used when no length is provided.</span></p>
<blockquote><p><span style="font-family: Arial; font-size: small;">Function New-RandomComplexPassword ()<br />
{<br />
param ( [int]$Length = 8 )<br />
#Usage: New-RandomComplexPassword 12<br />
$Assembly = Add-Type -AssemblyName System.Web<br />
$RandomComplexPassword = [System.Web.Security.Membership]::GeneratePassword($Length,2)<br />
Write-Output $RandomComplexPassword<br />
}</span></p></blockquote>
<p><span style="font-family: Arial; font-size: small;">As you may have noticed, with this version I make use of a .NET assembly instead of native Powershell cmdlets. This is because using the .NET assembly makes the code a lot shorter and faster. Next to that, the script I started to write before I found this assembly was huge and way more complex than it needed to be.<br />
For more information on the assembly I used, check the </span><a href="http://msdn.microsoft.com/en-us/library/system.web.security.membership.generatepassword.aspx"><span style="font-family: Arial; font-size: small;">MSDN page</span></a><span style="font-family: Arial; font-size: small;">.</span></p>
<div class="shr-publisher-951"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Powershell+function+to+create+a+random+password+with+complexity+requirement+http%3A%2F%2Fjeffwouters.nl%2F%3Fp%3D951" title="Post to Twitter"><img class="nothumb" src="http://jeffwouters.nl/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://jeffwouters.nl/index.php/2012/05/powershell-function-to-create-a-random-password-with-complexity-requirement/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PowerShell function to generate a random password</title>
		<link>http://jeffwouters.nl/index.php/2012/05/powershell-function-to-generate-a-random-password/</link>
		<comments>http://jeffwouters.nl/index.php/2012/05/powershell-function-to-generate-a-random-password/#comments</comments>
		<pubDate>Wed, 02 May 2012 11:04:48 +0000</pubDate>
		<dc:creator>Jeff Wouters</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://jeffwouters.nl/?p=939</guid>
		<description><![CDATA[This is part of one of my AD migration scripts which I find very useful. Whenever creating a user, I like to generate a random and complex password. The length of the password differs for each of my customers, so that’s something I define with a parameter added to this function: Function New-RandomPassword ($Length) { [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fpowershell-function-to-generate-a-random-password%2F' data-shr_title='PowerShell+function+to+generate+a+random+password'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F05%2Fpowershell-function-to-generate-a-random-password%2F' data-shr_title='PowerShell+function+to+generate+a+random+password'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p><span style="font-family: Arial; font-size: small;">This is part of one of my AD migration scripts which I find very useful.<br />
Whenever creating a user, I like to generate a random and complex password. The length of the password differs for each of my customers, so that’s something I define with a parameter added to this function:<br />
</span></p>
<blockquote><p><span style="font-family: Arial; font-size: small;">Function New-RandomPassword ($Length)<br />
{<br />
#Usage: New-RandomPassword 8<br />
$Random = New-Object System.Random<br />
$RandomPassword = (-join ([char[]](33..127) | Get-Random -Count $length))<br />
Write-Output $RandomPassword<br />
}</span></p></blockquote>
<p>Note that this one is very basic, no check in there for when both a higher- and lower case character, number and/or punctuation mark is included. For most of my customers the function above is sufficient <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-winkingsmile.png" alt="Knipogende emoticon" />I Hope you find this one useful <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/05/wlEmoticon-smile.png" alt="Glimlach" /></p>
<p>&nbsp;</p>
<p><span style="text-decoration: underline;">Update: Changed the script based on feedback from <a title="Shay Levy" href="http://www.twitter.com/ShayLevy">Shay Levy </a>through Twitter&#8230; thanks! <img src='http://jeffwouters.nl/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div class="shr-publisher-939"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=PowerShell+function+to+generate+a+random+password+http%3A%2F%2Fjeffwouters.nl%2F%3Fp%3D939" title="Post to Twitter"><img class="nothumb" src="http://jeffwouters.nl/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://jeffwouters.nl/index.php/2012/05/powershell-function-to-generate-a-random-password/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PowerShell &#8211; Having fun with Compare-Object in the 2012 Scripting Games</title>
		<link>http://jeffwouters.nl/index.php/2012/04/powershell-having-fun-with-compare-object-in-the-2012-scripting-games/</link>
		<comments>http://jeffwouters.nl/index.php/2012/04/powershell-having-fun-with-compare-object-in-the-2012-scripting-games/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 08:55:14 +0000</pubDate>
		<dc:creator>Jeff Wouters</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://jeffwouters.nl/?p=916</guid>
		<description><![CDATA[This year I was competing in the Windows PowerShell Scripting Games 2012. One of the exercises in the Beginners class was to compare two folders. Ed Wilson (Microsoft ScriptingGuy) provided a script to create two folders with a bunch of files in them and delete one file from each folder. So, I started to script… [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F04%2Fpowershell-having-fun-with-compare-object-in-the-2012-scripting-games%2F' data-shr_title='PowerShell+-+Having+fun+with+Compare-Object+in+the+2012+Scripting+Games'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F04%2Fpowershell-having-fun-with-compare-object-in-the-2012-scripting-games%2F' data-shr_title='PowerShell+-+Having+fun+with+Compare-Object+in+the+2012+Scripting+Games'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p><span style="color: #000000; font-family: Arial; font-size: small;">This year I was competing in the Windows PowerShell Scripting Games 2012.<br />
One of the exercises in the Beginners class was to </span><a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/04/05/2012-scripting-games-beginner-event-4-compare-two-folders.aspx"><span style="color: #000000; font-family: Arial; font-size: small;">compare two folders</span></a><span style="color: #000000; font-family: Arial; font-size: small;">.<br />
Ed Wilson (Microsoft ScriptingGuy) provided a script to create two folders with a bunch of files in them and delete one file from each folder.</span></p>
<p><span style="color: #000000; font-family: Arial; font-size: small;">So, I started to script… by using the Compare-Object cmdlet. This lets you compare objects (sounds kinda logical when looking at the name of the cmdlet, right? <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/04/wlEmoticon-winkingsmile5.png" alt="Knipogende emoticon" />).</span></p>
<p><span style="color: #000000; font-family: Arial; font-size: small;">But, then there was the Expert Commentary… here the expert provided explanation of the exercise and the solution. The solution he provided was as follows:</span></p>
<blockquote><p><span style="color: #000000; font-family: Arial; font-size: small;">$original = Get-Childitem -Path c:\1 | Sort-Object -Property Name<br />
$copy = Get-Childitem -Path c:\2 | Sort-Object -Property Name<br />
$difference = @(Compare-Object -ReferenceObject $original -DifferenceObject $copy -Property Name -PassThru)<br />
if ($difference.Count -eq 0) {<br />
Write-Host -ForegroundColor Green &#8216;Content is equal&#8217;<br />
} else {<br />
Write-Host -ForegroundColor Red &#8216;Content is different. Differences:&#8217;<br />
$difference<br />
}</span></p></blockquote>
<p><span style="color: #000000; font-family: Arial; font-size: small;">Now, this is a easy and good solution <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/04/wlEmoticon-smile5.png" alt="Glimlach" /><br />
In short (by removing code that’s not required for the functionality of the script), this will become something like:</span></p>
<blockquote><p><span style="color: #000000; font-family: Arial; font-size: small;">$original = Get-Childitem -Path c:\1 | Sort-Object -Property Name<br />
$copy = Get-Childitem -Path c:\2 | Sort-Object -Property Name<br />
$difference = @(Compare-Object -ReferenceObject $original -DifferenceObject $copy -Property Name -PassThru)<br />
</span></p></blockquote>
<p><span style="color: #000000; font-family: Arial; font-size: small;">This differs from the solution I came up with since I’m a big fan of “one liners” <img class="wlEmoticon wlEmoticon-hotsmile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/04/wlEmoticon-hotsmile4.png" alt="Verhitte emoticon" /><br />
My solution:</span></p>
<blockquote><p><span style="color: #000000; font-family: Arial; font-size: small;">Compare-Object –ReferenceObject (Get-ChildItem C:\1) –DifferenceObject (Get-ChildItem C:\2) –Passthru</span></p></blockquote>
<p><span style="color: #000000; font-family: Arial; font-size: small;">Now, yesterday one of my students (in a PowerShell workshop I’m giving) came up with an even shorter solution (and I was thinking my solution was bad-ass <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/04/wlEmoticon-winkingsmile5.png" alt="Knipogende emoticon" />):</span></p>
<blockquote><p><span style="color: #000000; font-family: Arial; font-size: small;">Compare-Object (Get-Childitem C:\1) (Get-ChildItem C:\2)</span></p></blockquote>
<p><span style="color: #000000; font-family: Arial; font-size: small;">This is because Compare-Object automatically knows that if you provide the objects, the first is the ReferenceObject and the second will be the DifferenceObject… so even an easier way <img class="wlEmoticon wlEmoticon-openmouthedsmile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/04/wlEmoticon-openmouthedsmile4.png" alt="Emoticon met brede lach" /></span></p>
<p><span style="color: #000000; font-family: Arial; font-size: small;">Now this is the strength of PowerShell… it’s very easy, short, intelligent and understandable… but you can still make it as complex as you want <img src='http://jeffwouters.nl/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </span></p>
<p><span style="color: #000000; font-family: Arial; font-size: small;"> </span></p>
<div class="shr-publisher-916"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=PowerShell+%E2%80%93+Having+fun+with+Compare-Object+in+the+2012+Scripting+Games+http%3A%2F%2Fjeffwouters.nl%2F%3Fp%3D916" title="Post to Twitter"><img class="nothumb" src="http://jeffwouters.nl/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://jeffwouters.nl/index.php/2012/04/powershell-having-fun-with-compare-object-in-the-2012-scripting-games/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Powershell function to rename a computer</title>
		<link>http://jeffwouters.nl/index.php/2012/04/powershell-function-to-rename-a-computer/</link>
		<comments>http://jeffwouters.nl/index.php/2012/04/powershell-function-to-rename-a-computer/#comments</comments>
		<pubDate>Fri, 20 Apr 2012 17:26:23 +0000</pubDate>
		<dc:creator>Jeff Wouters</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">http://jeffwouters.nl/?p=872</guid>
		<description><![CDATA[This is something I took from one of my larger deployment scripts and found it to be very useful and reusable. Just to give you a use case: In my situation the parameter $NewComputerName is calculated based on the device type (server, laptop or desktop), the IP range and a random number taken from a [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F04%2Fpowershell-function-to-rename-a-computer%2F' data-shr_title='Powershell+function+to+rename+a+computer'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fjeffwouters.nl%2Findex.php%2F2012%2F04%2Fpowershell-function-to-rename-a-computer%2F' data-shr_title='Powershell+function+to+rename+a+computer'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p><span style="font-family: Arial; font-size: small;">This is something I took from one of my larger deployment scripts and found it to be very useful and reusable.<br />
Just to give you a use case: In my situation the parameter $NewComputerName is calculated based on the device type (server, laptop or desktop), the IP range and a random number taken from a text file located on a file share. </span></p>
<p>I hope you find it useful <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="http://jeffwouters.nl/wp-content/uploads/2012/04/wlEmoticon-smile4.png" alt="Glimlach" /></p>
<blockquote><p><span style="font-family: Arial; font-size: small;">Function Rename-Computer ($NewComputerName)<br />
{<br />
# Get the current credential.<br />
$credential = Get-Credential</span></p>
<p><span style="font-family: Arial; font-size: small;">  # Get the current computer name<br />
$OldComputerName = $Env:ComputerName</p>
<p># Change the computer name.<br />
Get-WmiObject Win32_ComputerSystem -ComputerName $OldComputerName -Authentication 6 | ForEach-Object {$_.Rename($NewComputerName,$credential.GetNetworkCredential().Password,$credential.Username)}</span></p>
<p><span style="font-family: Arial; font-size: small;">  # Reboot the computer to let the change take affect.<br />
Shutdown.exe -r –t 7<br />
}</span></p></blockquote>
<div class="shr-publisher-872"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Powershell+function+to+rename+a+computer+http%3A%2F%2Fjeffwouters.nl%2F%3Fp%3D872" title="Post to Twitter"><img class="nothumb" src="http://jeffwouters.nl/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://jeffwouters.nl/index.php/2012/04/powershell-function-to-rename-a-computer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

