
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Creating a User Account in Active Directory with PowerShell</title>
	<atom:link href="http://www.leadfollowmove.com/archives/powershell/creating-a-user-account-in-active-directory-with-powershell/feed" rel="self" type="application/rss+xml" />
	<link>http://www.leadfollowmove.com/archives/powershell/creating-a-user-account-in-active-directory-with-powershell</link>
	<description>Adam Bell on Deployment, Automation, PowerShell et al</description>
	<lastBuildDate>Thu, 25 Feb 2010 23:14:19 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: AdamBell</title>
		<link>http://www.leadfollowmove.com/archives/powershell/creating-a-user-account-in-active-directory-with-powershell/comment-page-1#comment-249</link>
		<dc:creator>AdamBell</dc:creator>
		<pubDate>Tue, 17 Jul 2007 13:17:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.leadfollowmove.com/?p=44#comment-249</guid>
		<description>Hi Briano,

Nice way of doing it. I wrote a function (see sample code page) that does the same thing, but isn&#039;t as elegant.

It was something I wrote early on playing with PoSH, and so is VBScript centric. I like your PoSH way much better.

Time to ferret out the library file and update it ;)

Thanks for the comment.

Cheers

Adam</description>
		<content:encoded><![CDATA[<p>Hi Briano,</p>
<p>Nice way of doing it. I wrote a function (see sample code page) that does the same thing, but isn&#8217;t as elegant.</p>
<p>It was something I wrote early on playing with PoSH, and so is VBScript centric. I like your PoSH way much better.</p>
<p>Time to ferret out the library file and update it ;)</p>
<p>Thanks for the comment.</p>
<p>Cheers</p>
<p>Adam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Briano</title>
		<link>http://www.leadfollowmove.com/archives/powershell/creating-a-user-account-in-active-directory-with-powershell/comment-page-1#comment-248</link>
		<dc:creator>Briano</dc:creator>
		<pubDate>Tue, 17 Jul 2007 13:11:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.leadfollowmove.com/?p=44#comment-248</guid>
		<description>I used the following code to convert DN to FQDN:

#get the DN
$rootDSE = [ADSI]&quot;LDAP://RootDSE&quot;
$domainDN = $rootDSE.Get(&quot;DefaultNamingContext&quot;)

#convert the DN to FQDN
$domainFQDN =  $domainDN -replace(&quot;,dc=&quot;,&quot;.&quot;) -replace(&quot;dc=&quot;,&quot;&quot;)</description>
		<content:encoded><![CDATA[<p>I used the following code to convert DN to FQDN:</p>
<p>#get the DN<br />
$rootDSE = [ADSI]&#8220;LDAP://RootDSE&#8221;<br />
$domainDN = $rootDSE.Get(&#8220;DefaultNamingContext&#8221;)</p>
<p>#convert the DN to FQDN<br />
$domainFQDN =  $domainDN -replace(&#8220;,dc=&#8221;,&#8221;.&#8221;) -replace(&#8220;dc=&#8221;,&#8221;")</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter {faa780ce-0f0a-4c28-81d2-3667b71287fd}</title>
		<link>http://www.leadfollowmove.com/archives/powershell/creating-a-user-account-in-active-directory-with-powershell/comment-page-1#comment-39</link>
		<dc:creator>Peter {faa780ce-0f0a-4c28-81d2-3667b71287fd}</dc:creator>
		<pubDate>Mon, 12 Mar 2007 18:41:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.leadfollowmove.com/?p=44#comment-39</guid>
		<description>Yeargh, my above function is giving me problems today, I&#039;d like to retract this from the internet in general until I figure it out :)</description>
		<content:encoded><![CDATA[<p>Yeargh, my above function is giving me problems today, I&#8217;d like to retract this from the internet in general until I figure it out :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter {faa780ce-0f0a-4c28-81d2-3667b71287fd}</title>
		<link>http://www.leadfollowmove.com/archives/powershell/creating-a-user-account-in-active-directory-with-powershell/comment-page-1#comment-20</link>
		<dc:creator>Peter {faa780ce-0f0a-4c28-81d2-3667b71287fd}</dc:creator>
		<pubDate>Fri, 16 Feb 2007 21:41:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.leadfollowmove.com/?p=44#comment-20</guid>
		<description>Nevermind, I found the solution in pure C# and adapted it for my full-user-setup script.  Feel free to do...whatever...with it.

1. Link/citing source: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1204480&amp;SiteID=1

2. Calling lines of code:

#----------------
CreateHomeDirectory $username
$u.put(&quot;homeDirectory&quot;, $homeDirectory)
$u.put(&quot;homeDrive&quot;, $homeDrive)
$u.setInfo()
#--------------------

3. Function:

#---------------------
function CreateHomeDirectory
{
	param([string]$username)

	trap 
	{
		write-host &quot;ERROR on account: $username&quot;
		write-host &quot;ID: &quot; $_.ErrorID
		write-host &quot;Message: &quot;$_.Exception.Message
		
		break
	}
	
	$folderpath = &quot;{0}{1}&quot; -f $USER_ROOT_UNC, $username
	$folder = get-item $folderpath -ErrorAction SilentlyContinue 
	if (-not $folder)
	{
		#see http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1204480&amp;SiteID=1
		#this explains why you need to set three rules for one user.
		
		$folder = new-item $folderpath -itemtype directory -ErrorAction Stop
		#InheritanceFlags.ObjectInherit = 2
		#PropogationFlags.InheritOnly = 2
		$ar1 = new-object System.Security.AccessControl.FileSystemAccessRule($username,&quot;FullControl&quot;,2,2,&quot;Allow&quot;)

		#InheritanceFlags.ContainerInherit = 1
		#PropogationFlags.InheritOnly = 2
		$ar2 = new-object System.Security.AccessControl.FileSystemAccessRule($username,&quot;FullControl&quot;,1,2,&quot;Allow&quot;)

		$ar3 = new-object System.Security.AccessControl.FileSystemAccessRule($username,&quot;FullControl&quot;,&quot;Allow&quot;)
		
		
		$acl = get-acl $folder
		$acl.AddAccessRule($ar1)
		$acl.AddAccessRule($ar2)
		$acl.AddAccessRule($ar3)
		set-acl $folder $acl -ErrorAction Stop
	}
	else
	{
		#ERROR.
		#home directory shouldn&#039;t already exist for a brand new user.
		#this is a potential collision - need to manually resolve.
		throw &quot;user: $username - already has home directory of the same name.&quot;
	}
}</description>
		<content:encoded><![CDATA[<p>Nevermind, I found the solution in pure C# and adapted it for my full-user-setup script.  Feel free to do&#8230;whatever&#8230;with it.</p>
<p>1. Link/citing source: <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1204480&amp;SiteID=1" rel="nofollow">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1204480&amp;SiteID=1</a></p>
<p>2. Calling lines of code:</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
CreateHomeDirectory $username<br />
$u.put(&#8220;homeDirectory&#8221;, $homeDirectory)<br />
$u.put(&#8220;homeDrive&#8221;, $homeDrive)<br />
$u.setInfo()<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>3. Function:</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
function CreateHomeDirectory<br />
{<br />
	param([string]$username)</p>
<p>	trap<br />
	{<br />
		write-host &#8220;ERROR on account: $username&#8221;<br />
		write-host &#8220;ID: &#8221; $_.ErrorID<br />
		write-host &#8220;Message: &#8220;$_.Exception.Message</p>
<p>		break<br />
	}</p>
<p>	$folderpath = &#8220;{0}{1}&#8221; -f $USER_ROOT_UNC, $username<br />
	$folder = get-item $folderpath -ErrorAction SilentlyContinue<br />
	if (-not $folder)<br />
	{<br />
		#see <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1204480&amp;SiteID=1" rel="nofollow">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1204480&amp;SiteID=1</a><br />
		#this explains why you need to set three rules for one user.</p>
<p>		$folder = new-item $folderpath -itemtype directory -ErrorAction Stop<br />
		#InheritanceFlags.ObjectInherit = 2<br />
		#PropogationFlags.InheritOnly = 2<br />
		$ar1 = new-object System.Security.AccessControl.FileSystemAccessRule($username,&#8221;FullControl&#8221;,2,2,&#8221;Allow&#8221;)</p>
<p>		#InheritanceFlags.ContainerInherit = 1<br />
		#PropogationFlags.InheritOnly = 2<br />
		$ar2 = new-object System.Security.AccessControl.FileSystemAccessRule($username,&#8221;FullControl&#8221;,1,2,&#8221;Allow&#8221;)</p>
<p>		$ar3 = new-object System.Security.AccessControl.FileSystemAccessRule($username,&#8221;FullControl&#8221;,&#8221;Allow&#8221;)</p>
<p>		$acl = get-acl $folder<br />
		$acl.AddAccessRule($ar1)<br />
		$acl.AddAccessRule($ar2)<br />
		$acl.AddAccessRule($ar3)<br />
		set-acl $folder $acl -ErrorAction Stop<br />
	}<br />
	else<br />
	{<br />
		#ERROR.<br />
		#home directory shouldn&#8217;t already exist for a brand new user.<br />
		#this is a potential collision &#8211; need to manually resolve.<br />
		throw &#8220;user: $username &#8211; already has home directory of the same name.&#8221;<br />
	}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter {faa780ce-0f0a-4c28-81d2-3667b71287fd}</title>
		<link>http://www.leadfollowmove.com/archives/powershell/creating-a-user-account-in-active-directory-with-powershell/comment-page-1#comment-19</link>
		<dc:creator>Peter {faa780ce-0f0a-4c28-81d2-3667b71287fd}</dc:creator>
		<pubDate>Fri, 16 Feb 2007 19:03:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.leadfollowmove.com/?p=44#comment-19</guid>
		<description>I&#039;ve built a similar script to create user accounts. My big question is: have you attempted to tackle setting up home folders? As far as I can tell, doing that in PowerShell is uncharted territory. Anyway, your user creation script is way nicer than mine :)</description>
		<content:encoded><![CDATA[<p>I&#8217;ve built a similar script to create user accounts. My big question is: have you attempted to tackle setting up home folders? As far as I can tell, doing that in PowerShell is uncharted territory. Anyway, your user creation script is way nicer than mine :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

