<?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/"
	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>Comments on: Tips when scripting users in SBS 2008</title>
	<atom:link href="http://blog.powershell.no/2009/01/07/tips-when-scripting-users-in-sbs-2008/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.powershell.no/2009/01/07/tips-when-scripting-users-in-sbs-2008/</link>
	<description>On Windows PowerShell and other admin-related topics</description>
	<lastBuildDate>Fri, 09 Dec 2011 10:08:22 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Anders</title>
		<link>http://blog.powershell.no/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-394</link>
		<dc:creator><![CDATA[Anders]]></dc:creator>
		<pubDate>Fri, 12 Nov 2010 10:51:36 +0000</pubDate>
		<guid isPermaLink="false">http://janegilring.wordpress.com/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-394</guid>
		<description><![CDATA[Oups - and a nother thing should be mentioned. The TS-settings are taken from a template user, that must be created prior to running the script (in my script this user is called &#039;Support&#039;). Alternatively the data could be exported in some way and then imported. This procedure seems more simple but does require a template user.]]></description>
		<content:encoded><![CDATA[<p>Oups &#8211; and a nother thing should be mentioned. The TS-settings are taken from a template user, that must be created prior to running the script (in my script this user is called &#8216;Support&#8217;). Alternatively the data could be exported in some way and then imported. This procedure seems more simple but does require a template user.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anders</title>
		<link>http://blog.powershell.no/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-393</link>
		<dc:creator><![CDATA[Anders]]></dc:creator>
		<pubDate>Fri, 12 Nov 2010 10:44:58 +0000</pubDate>
		<guid isPermaLink="false">http://janegilring.wordpress.com/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-393</guid>
		<description><![CDATA[Thank YOU :)]]></description>
		<content:encoded><![CDATA[<p>Thank YOU <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anders</title>
		<link>http://blog.powershell.no/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-392</link>
		<dc:creator><![CDATA[Anders]]></dc:creator>
		<pubDate>Fri, 12 Nov 2010 10:39:12 +0000</pubDate>
		<guid isPermaLink="false">http://janegilring.wordpress.com/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-392</guid>
		<description><![CDATA[Edit:
This line should have been removed/is not necessary:
$TimeSpanZero = New-TimeSpan -Days 0 -Hours 0 -Minutes 0 -Seconds 0]]></description>
		<content:encoded><![CDATA[<p>Edit:<br />
This line should have been removed/is not necessary:<br />
$TimeSpanZero = New-TimeSpan -Days 0 -Hours 0 -Minutes 0 -Seconds 0</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan Egil Ring</title>
		<link>http://blog.powershell.no/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-391</link>
		<dc:creator><![CDATA[Jan Egil Ring]]></dc:creator>
		<pubDate>Fri, 12 Nov 2010 08:49:14 +0000</pubDate>
		<guid isPermaLink="false">http://janegilring.wordpress.com/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-391</guid>
		<description><![CDATA[Great, thanks for sharing your revised code!]]></description>
		<content:encoded><![CDATA[<p>Great, thanks for sharing your revised code!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anders from Randers (DK)</title>
		<link>http://blog.powershell.no/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-390</link>
		<dc:creator><![CDATA[Anders from Randers (DK)]]></dc:creator>
		<pubDate>Fri, 12 Nov 2010 07:29:43 +0000</pubDate>
		<guid isPermaLink="false">http://janegilring.wordpress.com/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-390</guid>
		<description><![CDATA[Thanks for this code!

Inspired by this thread I have made a revision including terminal services settings, that are not created when not using the SBS Wizard.

Also some of the data is unnecessary in the CSV-fil, because they can be made of other informations already present:
name, displayname, userprincipalname and parentcontainer

Since i don&#039;t use telephone and department they are shaved of in my code. They can of course be found in the original script.

Here goes:

Clear-Host

$UsersCSVPath 	= &quot;D:\JMA\brugere.csv&quot;
$LocalDomain 	= (([DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Domains &#124; foreach { $_.forest.name }) -as [string]
$ParentContainer= &quot;$LocalDomain/MyBusiness/Users/SBSUsers&quot;
$Password 		= &quot;07Navision&quot; 

$TimeSpanZero   = New-TimeSpan -Days 0 -Hours 0 -Minutes 0 -Seconds 0


function WhatIsTehName ([string]$GivenName,[string]$sn) {
			
		if (($GivenName) -and ($sn)) {
			return &quot;$GivenName $sn&quot;
		} else {
			if ($_.givenname) {
				return $GivenName
			} else {
				return $null
			}
		}	
		
}

function CreateUsersFromCSV {
	   
	import-csv $UsersCSVPath &#124; 
		foreach-object {
			
			$Name = WhatIsTehName $_.givenname $_.sn 
			
			if ($Name) {
				
				$username = $_.SamAccountName				

				$TsSettings = get-qaduser -Identity support  &#124; 
					select-object TsAllowLogon,TsRemoteControl,TsMaxDisconnectionTime,TsMaxConnectionTime,TsMaxIdleTime,TsReconnectionAction,TsBrokenConnectionAction,TsConnectClientDrives,TsConnectPrinterDrives,TsDefaultToMainPrinter
				
				if (!(get-qaduser -SamAccountName $username)){
				
					try {
					
						New-QADUser `
						-FirstName $_.givenname `
						-LastName $_.sn `
						-ParentContainer $ParentContainer `
						-SamAccountName $username `
						-Name $Name `
						-displayname $Name `
						-Description $_.description `
						-userprincipalname &quot;$username@$LocalDomain&quot; `
						-UserPassword $Password &#124; 
							Get-QADUser &#124;
								Set-QADUser `
									-TsAllowLogon $TsSettings.TsAllowLogon `
									-TsRemoteControl $TsSettings.TsRemoteControl `
									-TsMaxDisconnectionTime $TsSettings.TsMaxConnectionTime `
									-TsMaxConnectionTime $TsSettings.TsMaxDisconnectionTime `
									-TsMaxIdleTime $TsSettings.TsMaxIdleTime `
									-TsReconnectionAction $TsSettings.TsReconnectionAction`
									-TsBrokenConnectionAction $TsSettings.TsBrokenConnectionAction `
									-TsConnectClientDrives $TsSettings.TsConnectClientDrives `
									-TsConnectPrinterDrives $TsSettings.TsConnectPrinterDrives `
									-TsDefaultToMainPrinter $TsSettings.TsDefaultToMainPrinter &#124;
								Enable-QADUser
						
					} catch {
						#$Error[0]
						Write-Host $_.exception.gettype().fullname
						Write-Host $_.exception.message
					}
				} else {
					Write-Host &quot;$Name ($username) allready created (No Problemo)&quot; -BackgroundColor yellow -ForegroundColor Green
				}
			} 
		}
}

if (Test-Path $UsersCSVPath) {
	CreateUsersFromCSV
}]]></description>
		<content:encoded><![CDATA[<p>Thanks for this code!</p>
<p>Inspired by this thread I have made a revision including terminal services settings, that are not created when not using the SBS Wizard.</p>
<p>Also some of the data is unnecessary in the CSV-fil, because they can be made of other informations already present:<br />
name, displayname, userprincipalname and parentcontainer</p>
<p>Since i don&#8217;t use telephone and department they are shaved of in my code. They can of course be found in the original script.</p>
<p>Here goes:</p>
<p>Clear-Host</p>
<p>$UsersCSVPath 	= &#8220;D:\JMA\brugere.csv&#8221;<br />
$LocalDomain 	= (([DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Domains | foreach { $_.forest.name }) -as [string]<br />
$ParentContainer= &#8220;$LocalDomain/MyBusiness/Users/SBSUsers&#8221;<br />
$Password 		= &#8220;07Navision&#8221; </p>
<p>$TimeSpanZero   = New-TimeSpan -Days 0 -Hours 0 -Minutes 0 -Seconds 0</p>
<p>function WhatIsTehName ([string]$GivenName,[string]$sn) {</p>
<p>		if (($GivenName) -and ($sn)) {<br />
			return &#8220;$GivenName $sn&#8221;<br />
		} else {<br />
			if ($_.givenname) {<br />
				return $GivenName<br />
			} else {<br />
				return $null<br />
			}<br />
		}	</p>
<p>}</p>
<p>function CreateUsersFromCSV {</p>
<p>	import-csv $UsersCSVPath |<br />
		foreach-object {</p>
<p>			$Name = WhatIsTehName $_.givenname $_.sn </p>
<p>			if ($Name) {</p>
<p>				$username = $_.SamAccountName				</p>
<p>				$TsSettings = get-qaduser -Identity support  |<br />
					select-object TsAllowLogon,TsRemoteControl,TsMaxDisconnectionTime,TsMaxConnectionTime,TsMaxIdleTime,TsReconnectionAction,TsBrokenConnectionAction,TsConnectClientDrives,TsConnectPrinterDrives,TsDefaultToMainPrinter</p>
<p>				if (!(get-qaduser -SamAccountName $username)){</p>
<p>					try {</p>
<p>						New-QADUser `<br />
						-FirstName $_.givenname `<br />
						-LastName $_.sn `<br />
						-ParentContainer $ParentContainer `<br />
						-SamAccountName $username `<br />
						-Name $Name `<br />
						-displayname $Name `<br />
						-Description $_.description `<br />
						-userprincipalname &#8220;$username@$LocalDomain&#8221; `<br />
						-UserPassword $Password |<br />
							Get-QADUser |<br />
								Set-QADUser `<br />
									-TsAllowLogon $TsSettings.TsAllowLogon `<br />
									-TsRemoteControl $TsSettings.TsRemoteControl `<br />
									-TsMaxDisconnectionTime $TsSettings.TsMaxConnectionTime `<br />
									-TsMaxConnectionTime $TsSettings.TsMaxDisconnectionTime `<br />
									-TsMaxIdleTime $TsSettings.TsMaxIdleTime `<br />
									-TsReconnectionAction $TsSettings.TsReconnectionAction`<br />
									-TsBrokenConnectionAction $TsSettings.TsBrokenConnectionAction `<br />
									-TsConnectClientDrives $TsSettings.TsConnectClientDrives `<br />
									-TsConnectPrinterDrives $TsSettings.TsConnectPrinterDrives `<br />
									-TsDefaultToMainPrinter $TsSettings.TsDefaultToMainPrinter |<br />
								Enable-QADUser</p>
<p>					} catch {<br />
						#$Error[0]<br />
						Write-Host $_.exception.gettype().fullname<br />
						Write-Host $_.exception.message<br />
					}<br />
				} else {<br />
					Write-Host &#8220;$Name ($username) allready created (No Problemo)&#8221; -BackgroundColor yellow -ForegroundColor Green<br />
				}<br />
			}<br />
		}<br />
}</p>
<p>if (Test-Path $UsersCSVPath) {<br />
	CreateUsersFromCSV<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan Egil Ring</title>
		<link>http://blog.powershell.no/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-47</link>
		<dc:creator><![CDATA[Jan Egil Ring]]></dc:creator>
		<pubDate>Wed, 07 Oct 2009 20:16:23 +0000</pubDate>
		<guid isPermaLink="false">http://janegilring.wordpress.com/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-47</guid>
		<description><![CDATA[Rodeca, good point! Glad I could help.]]></description>
		<content:encoded><![CDATA[<p>Rodeca, good point! Glad I could help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rodeca</title>
		<link>http://blog.powershell.no/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-46</link>
		<dc:creator><![CDATA[Rodeca]]></dc:creator>
		<pubDate>Wed, 07 Oct 2009 10:03:16 +0000</pubDate>
		<guid isPermaLink="false">http://janegilring.wordpress.com/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-46</guid>
		<description><![CDATA[Great, thanks

I&#039;ll keep using (for a while, at least) my VBS + Excel (hacked at MS scriptcenter), but you told me what I was looking for: set &quot;my&quot; users as if they were added using that wizard.

Rodeca
P.S. Besides your &quot;laziness&quot; reason, there is another one: avoid mistakes &amp; errata]]></description>
		<content:encoded><![CDATA[<p>Great, thanks</p>
<p>I&#8217;ll keep using (for a while, at least) my VBS + Excel (hacked at MS scriptcenter), but you told me what I was looking for: set &#8220;my&#8221; users as if they were added using that wizard.</p>
<p>Rodeca<br />
P.S. Besides your &#8220;laziness&#8221; reason, there is another one: avoid mistakes &amp; errata</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yves</title>
		<link>http://blog.powershell.no/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-8</link>
		<dc:creator><![CDATA[Yves]]></dc:creator>
		<pubDate>Thu, 02 Apr 2009 09:20:33 +0000</pubDate>
		<guid isPermaLink="false">http://janegilring.wordpress.com/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-8</guid>
		<description><![CDATA[I&#039;ll try that out, thank you very much.

Regards,

Yves]]></description>
		<content:encoded><![CDATA[<p>I&#8217;ll try that out, thank you very much.</p>
<p>Regards,</p>
<p>Yves</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan Egil Ring</title>
		<link>http://blog.powershell.no/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-6</link>
		<dc:creator><![CDATA[Jan Egil Ring]]></dc:creator>
		<pubDate>Tue, 31 Mar 2009 19:15:21 +0000</pubDate>
		<guid isPermaLink="false">http://janegilring.wordpress.com/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-6</guid>
		<description><![CDATA[Hi Yves!

I`m glad the sample helped you.

Here is another sample which also creates the homefolders:
import-csv &quot;C:\import.csv&quot; &#124; foreach-object { $username = $_.samaccountname;New-QADUser -FirstName $_.givenname -LastName $_.sn -ParentContainer $_.ParentContainer -SamAccountName $_.samaccountname -Name $_.name -displayname $_.displayname -userprincipalname $_.userprincipalname -Company $_.company -Department $_.department -PhoneNumber $_.telephonenumber &#124; Set-QADUser -UserPassword Passord1 -ObjectAttributes @{homeDrive= &#039;F:&#039; ;homeDirectory= &quot;\\domain.local\Data\Users\$username&quot; ;scriptPath=&#039;netlogon.cmd&#039;}&#124;Enable-QADUser;New-Item -Path \\domain.local\Data\Users\$username -type directory}

For setting NTFS security on the homefolders I`ve used Eric McCarty`s set-FileSystemSecurity function available on his blog: http://ewmccarty.spaces.live.com/blog/cns!CE2AE9EFF99E6598!131.entry

Hint: Install PowerShell Community Extensions (PSCX) SCX 1.1.1 from http://www.codeplex.com/PowerShellCX
and install it.

Then grant the &quot;SeRestore&quot; privilege to the PowerShell process (needed for the set-FileSystemSecurity function to be able to set permissions):

PS &gt; $SeRestore = new-object Pscx.Interop.TokenPrivilege &quot;SeRestorePrivilege&quot;, $true

Then, grant it to the current process&#039;s token (powershell.exe):

PS &gt; Set-Privilege $SeRestore

Then run set-FileSystemSecurity C:\homefolders domain.local]]></description>
		<content:encoded><![CDATA[<p>Hi Yves!</p>
<p>I`m glad the sample helped you.</p>
<p>Here is another sample which also creates the homefolders:<br />
import-csv &#8220;C:\import.csv&#8221; | foreach-object { $username = $_.samaccountname;New-QADUser -FirstName $_.givenname -LastName $_.sn -ParentContainer $_.ParentContainer -SamAccountName $_.samaccountname -Name $_.name -displayname $_.displayname -userprincipalname $_.userprincipalname -Company $_.company -Department $_.department -PhoneNumber $_.telephonenumber | Set-QADUser -UserPassword Passord1 -ObjectAttributes @{homeDrive= &#8216;F:&#8217; ;homeDirectory= &#8220;\\domain.local\Data\Users\$username&#8221; ;scriptPath=&#8217;netlogon.cmd&#8217;}|Enable-QADUser;New-Item -Path \\domain.local\Data\Users\$username -type directory}</p>
<p>For setting NTFS security on the homefolders I`ve used Eric McCarty`s set-FileSystemSecurity function available on his blog: <a href="http://ewmccarty.spaces.live.com/blog/cns!CE2AE9EFF99E6598!131.entry" rel="nofollow">http://ewmccarty.spaces.live.com/blog/cns!CE2AE9EFF99E6598!131.entry</a></p>
<p>Hint: Install PowerShell Community Extensions (PSCX) SCX 1.1.1 from <a href="http://www.codeplex.com/PowerShellCX" rel="nofollow">http://www.codeplex.com/PowerShellCX</a><br />
and install it.</p>
<p>Then grant the &#8220;SeRestore&#8221; privilege to the PowerShell process (needed for the set-FileSystemSecurity function to be able to set permissions):</p>
<p>PS &gt; $SeRestore = new-object Pscx.Interop.TokenPrivilege &#8220;SeRestorePrivilege&#8221;, $true</p>
<p>Then, grant it to the current process&#8217;s token (powershell.exe):</p>
<p>PS &gt; Set-Privilege $SeRestore</p>
<p>Then run set-FileSystemSecurity C:\homefolders domain.local</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yves</title>
		<link>http://blog.powershell.no/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-5</link>
		<dc:creator><![CDATA[Yves]]></dc:creator>
		<pubDate>Fri, 27 Mar 2009 14:14:45 +0000</pubDate>
		<guid isPermaLink="false">http://janegilring.wordpress.com/2009/01/07/tips-when-scripting-users-in-sbs-2008/#comment-5</guid>
		<description><![CDATA[Jan,

your powershell sample helped me out alot. I had some problems with setting the homedirectory and drive. Now it all works fine. In my older 2000 environment I had an automated script that also created the user folders, how do you do that after importing the users? Anyway, thanks alot for sharing this info.

Regards,

Yves]]></description>
		<content:encoded><![CDATA[<p>Jan,</p>
<p>your powershell sample helped me out alot. I had some problems with setting the homedirectory and drive. Now it all works fine. In my older 2000 environment I had an automated script that also created the user folders, how do you do that after importing the users? Anyway, thanks alot for sharing this info.</p>
<p>Regards,</p>
<p>Yves</p>
]]></content:encoded>
	</item>
</channel>
</rss>

