Ben’s Blog

benball.net
March 9th, 2010

Provision user home directories with PowerShell

A major part of our transition at work from a Novell Netware backend to Microsoft Windows Server 2008 R2 involved provisioning user accounts in Active Directory and fleshing out all the individual accounts with profile paths and home directories.  Fortunately we didn’t have to create the accounts, as we had been running Novell Identity Manager for some time, populating AD with accounts from eDirectory, along with basic user information, but the existing home directory information was not going to be valid on the new backend filesystem (Server 2008 R2 DFS + highly-available file cluster) so we needed a way to bulk change the account information, create home directories for each user (approximately 1700 users) and assign permissions.

Time and budget didn’t allow us to bring in external parties or purchase third-party migration tools, so we made the decision to do the entire thing with PowerShell.

PowerShell is one of those things which has been kicking around for a while, but not that many Windows admins have had to get their hands dirty with it.  I certainly hadn’t, so was a complete PowerShell newbie.  As such, this is my first proper script and I’m rather stupidly proud of it.

  1. $csv=Read-Host "Enter Path to CSV"

  2. $users=Import-Csv $csv

  3. #Create Home Directories

  4. $users | ForEach-Object {mkdir($_.’HomeDirectory’)}

  5. #Assign Access Rights

  6. foreach ($user in $users)

  7. {

  8. $account="DOMAIN\"+$user.LoginName

  9. $homedir=$user.HomeDirectory

  10. $rights=[System.Security.AccessControl.FileSystemRights]::FullControl

  11. $inheritance=[System.Security.AccessControl.InheritanceFlags]"ContainerInherit,ObjectInherit"

  12. $propagation=[System.Security.AccessControl.PropagationFlags]::None

  13. $allowdeny=[System.Security.AccessControl.AccessControlType]::Allow

  14. $dirACE=New-Object System.Security.AccessControl.FileSystemAccessRule ($account,$rights,$inheritance,$propagation,$allowdeny)

  15. $dirACL=Get-Acl $homedir

  16. $dirACL.AddAccessRule($dirACE)

  17. Set-Acl $homedir $dirACL

  18. Write-Host $homedir access rights assigned

  19. }

Obviously there are bits and pieces of this script which are particular to my own environment, but it should adjust to any similar situation.  I was importing data from multiple CSVs which were populated by student year levels – we are a K-12 school so that’s fairly important information, and determines what the users have access to, and that data is easier to manipulate via CSV.  I also had to populate a lot of the home directory information so that the CSV was accurate.  The CSVs only contained login information and home directory fields from AD:

  1. Get-QADUser | Select-Object SamAccountName,HomeDirectory

So, if you don’t need to handle multiple groups of users, you could replace the $csv variables with a similar query rather than use a CSV.

In the CSV, SamAccountName and HomeDirectory were mapped to columns headed LoginName and HomeDirectory respectively.  No real reason, just what I was using at the time.  The home directory data was the full UNC path to the user’s home directory.  The assumption is that the path doesn’t already exist, but if it does then the mkdir section of the script which creates each folder will simply bring up a “file already exists” error and continue onto the next instance.

The tricky bit was assigning user permissions, which is why I needed the SamAccountName data.  The permissions are assigned using .NET security classes, but they do assume that the inherited permissions on each folder are already correct.  This script doesn’t overwrite the ACL or grant the user exclusive ownership over the home directory, but simply adds the user to the ACL with Full Control, and allows those rights to flow to child objects.  It basically replicates that same permissions you get when specifying a home directory for a user using the Active Directory Users and Computers snap-in.

For 1700 users this script took about two hours to run, but worked flawlessly and meant that when students came barrelling in the following week, they actually had somewhere to store their files :-)

Don Jones’ series of TechNet articles about automating user provisioning were invaluable in my research, as was the purchase of PowerShell Plus, at the recommendation of @leadfollowmove.  And no, I’m not getting any kickbacks from the company – I purchased it fair and square.  If you’re a PowerShell newbie, many of the problems you encounter in the early days come back to not knowing what it is that you don’t know.  PowerShell Plus gives you a really useful visual over what’s happening with your scripts and variables, as well as offering guidance on available options and query logic.  Saves a lot of hair-pulling and teeth-gnashing.

And NOW if the company would like to offer me some kickbacks, I’m sure I will be amenable…

March 9th, 2010

How to use Group Policy to Enabled/Disable Outlook 2010 Social Connector (a.k.a. People Pane)

There is an awesome new feature coming in Outlook 2010 call the Outlook Social Connector (a.k.a. People Pane) that allows you to view all the recent relevant status updates and emails from that person. This feature also enables third parties (i.e. Facebook, Twitter & Linkedin) to make connectors so that the view can contain information from a variety of sources.

Outlook2010_PeopleView

User can turn this option on and off fairly easily under the “People Pane” option under the “View” tab in the Outlook Ribbon.

image

However some (out of touch) IT organisations might not want this feature enabled in your organisation and so there is a registry kill switch that can be controlled via group policy to enable/disable this option.

Key: HKCU\Software\Microsoft\Office\Outlook\SocialConnector

Value: RunOSC (REG_DWORD)

Data: 0 = Disabled

Data: 1 = Enabled

image

To control this option edit a Group Policy Object that is applied to all the users in your organisation navigate to Users Configuration > Preferences >Windows Settings > Registry. Then click on Action > New > Registry Item type Software\Microsoft\Office\Outlook\SocialConnector into the Key Path field then type RunOSC into the Value Name field and 1 in the Value Data field and click OK.

image

Alternatively you can click on the file image below to download the XML group policy preference file with this already setting configured. Once you downloaded the file just drag it into the Group Policy Preference Registry section and it will automatically create the setting.

Once this setting is applied you can see this “People Pane” option is no longer visible in the “View” tab.

image

Note: This also fixes the issue of the People Pane not showing in for some users who installed Office 2010 Beta.

September 10th, 2009

Ankle Revisited…

So for all those people asking …    here is the ankle x-ray post surgery.

ankle screws

Yes, the screws are still in there…

Ben.

September 10th, 2009

Microsoft Deployment Toolkit 2010 Now Released

Get ready to deploy Windows 7 and Windows Server 2008 R2 with the final release of Microsoft Deployment Toolkit 2010

Click here to download MDT now. (http://go.microsoft.com/fwlink/?LinkId=159061)

As you prepare to deploy Windows® 7 and Windows Server® 2008 R2, get a jump start with Microsoft® Deployment Toolkit (MDT) 2010. Leverage this Solution Accelerator to achieve efficient, cost-effective deployment of Windows 7 and Windows Server 2008 R2.

MDT is the recommended process and toolset to automate desktop and server deployment. MDT provides you with the following benefits:

  • Unified tools and processes required for desktop and server deployment in a common deployment console and collection of guidance.
  • Reduced deployment time and standardized desktop and server images, along with improved security and ongoing configuration management.
  • Fully automated Zero Touch Installation deployments by leveraging System Center Configuration Manager 2007 Service Pack 2 Release Candidate and Windows deployment tools. For those without a System Center Configuration Manager 2007 infrastructure, MDT leverages Windows deployment tools for Lite Touch Installation deployments.

MDT 2010 includes new features such as flexible driver management, optimized user interface workflow, and Windows PowerShellTM command line interface to help simplify deployment and make your job easier. Deploy faster and more easily with MDT 2010.

New in MDT 2010

Improvements in MDT 2010 allow you to:

  • Access deployment shares from anywhere on the network and replicate files and settings across organizational boundaries or sites.
  • Organize and manage drivers, operating systems, applications, packages, and task sequences with an improved UI.
  • Automate UI functionality using the new Windows PowerShell command line interface.

Next steps

September 8th, 2009

TechEd 2009

Yes I’m at Teched this year.

Hoping to blog more tomorrow.

Ben