Quest Set-QADUser -HomeDirectory

Posted on 2010-01-08
Last Modified: 2012-05-08
I am using the Quest Active Roles set-QADUser -Homedirectory with a script to update users from a excel file.  All works OK and the Homedirectory is updated in the user's profile, however, the actual folder is not created.  If I apply the setting in the user profile, the folder is created, so I know that the homedirectory folder is valid.  Any ideas on what I need to do so that the folder is created via the script.
Thanks in advance
Question by:ajwellman
    LVL 70

    Assisted Solution

    by:Chris Dent

    You need to create the folder within the script. I know that's a bit of a repeat of what you've said above, but the create operation that takes place when you set this in the GUI is a function of the GUI, not a function of AD.

    The simplest way would be to use:

    New-Item "WhateverPath" -Type Directory

    Does it also need to set permissions as well?


    Author Comment

    Thanks for the info.  I thought that I would be able to create the directory with the cmdlet.  I have a vbscript that uses LDAP to create a user and then just sets the homedirectory property and it creates the corresponding folder with the proper permissions.  If I have to create the folder, then it will have to have the permissions set to give the user full control as it does when created using the GUI.  Do you have any examples on how to do that.  I am quite new to powershell scripting.
    Thanks again for your help.
    LVL 1

    Accepted Solution

    The below, assuming that $user is the object captured via get-qaduser, should work.
    HomeDirRoot: is set to the full UNC path to where the folder will be located. For instance, \\server1\storage\homes.

    As you can see, setting permissions is a bit clunky in Powershell (at least v1, I haven't kept up with v2).

    This will create a directory in HomeDirRoot:\ with the users samaccountname as the folder name, set the folder to inherit permissions from HomeDirRoot:\, then give the user modify access to it as well.

    That's how I do it, anyways. May be (and probably are) better ways, but it works.
    New-PSDrive -Name HomeDirRoot -Root "\\server\share\Homedirectoryroot" -PSProvider FileSystem
    $Inherit = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit, ObjectInherit"
    $propogation = [System.Security.AccessControl.PropagationFlags]"None"
    # Test for existing directory, error if found, create if not
    if (!(Test-Path "HomeDirRoot:\$($user.samaccountname)")){
       New-Item "HomeDirRoot:\$($user.samaccountname)" -type directory
       $ACLBase = Get-Acl HomeDirRoot:\
       $AddACL = "yourdomain\$($user.samaccountname)", "Modify", $Inherit, $propogation, "Allow"
       $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $AddACL
       $ACLBase | Set-Acl "HomeDirRoot:\$($user.samaccountname)"
    } else {
       write-host "Directory $($user.samaccountname) already exists"

    Open in new window


    Author Closing Comment

    This works great and much neater than I was trying to do.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Why would I want to create a function for tracking messages? I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once…
    Set OWA language and time zone in Exchange for individuals, all users or per database.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now