+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, PowerShell Script Error in Coding and Web Development; Thanks in advance for any help. I have a script that I ran all of last year to create students, ...
  1. #1

    Join Date
    Jan 2011
    Location
    Anderson
    Posts
    35
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    PowerShell Script Error

    Thanks in advance for any help.

    I have a script that I ran all of last year to create students, home directories, and set permissions. All ran fine with no problems. I attempted to run it yesterday and got the following error:


    Set-Acl : Attempted to perform an unauthorized operation.
    At C:\Users\djameson\Desktop\ADAccounts\HD Rights.ps1:29 char:9
    + set-acl <<<< -aclobject $acl $directory
    + CategoryInfo : PermissionDenied: (\\rmsdc01\home$\students\sw19
    38:String) [Set-Acl], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.Pow
    erShell.Commands.SetAclCommand



    Everything in the script is created but the permissions. As far as I know, no changes have been made to the server, my workstation, the script....I am a domain admin so rights shouldn't be an issue. I have executed the script from PowerShell with "run as administrator". Nothing seems to make a difference.

    I can manually add the permissions without any problem. Any ideas as to what may be causing this issue?

    Thanks again for your time and suggestions.

  2. #2

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,168
    Thank Post
    98
    Thanked 319 Times in 261 Posts
    Blog Entries
    4
    Rep Power
    113
    Was this a one-off error for that particular directory, or did it crop up repeatedly?

    Could we see the code?

  3. #3

    Join Date
    Jan 2011
    Location
    Anderson
    Posts
    35
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks for the quick response.

    It happen on 7 servers x 7 home directory folders. The code to set the home directory permissions:

    ## Modify Permissions on HomeDir

    $userSID= (Get-QADUser -samaccountname $USERNAME).sid
    # Write-Host $userSID
    $directory = $HOMEDIRECTORY
    $inherit = [system.security.accesscontrol.InheritanceFlags]"ContainerInherit, ObjectInherit"
    $propagation = [system.security.accesscontrol.PropagationFlags]"None"
    $acl = Get-Acl $directory
    $accessrule = New-Object system.security.AccessControl.FileSystemAccessRule ($userSID, "FullControl", $inherit, $propagation, "Allow")
    $acl.AddAccessRule($accessrule)
    set-acl -aclobject $acl $directory
    Write-Host "============ Home Directory Rights Set ============" -foregroundcolor Cyan

    Thanks again.

  4. #4

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,168
    Thank Post
    98
    Thanked 319 Times in 261 Posts
    Blog Entries
    4
    Rep Power
    113
    This might help - https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=418906&SiteID=99

    I
    t seems there might be some issue if you don't explicitly have the TakeOwnership permission over the folder.

  5. #5

    Join Date
    Jan 2011
    Location
    Anderson
    Posts
    35
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks.

    I'll take a look but again, no changes on my account since last year (or ever actually) and it ran fine. I'll let you know if I am able to solve this. I really hate losing the use of the script as it really saves me a good bit of time in creating new student accounts.

    Thanks again.

  6. #6

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,168
    Thank Post
    98
    Thanked 319 Times in 261 Posts
    Blog Entries
    4
    Rep Power
    113
    Were the folders created differently at all this year?

  7. #7

    Join Date
    Jan 2011
    Location
    Anderson
    Posts
    35
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Not intentionally. I used a variation of the script a couple months ago to move elementary students to the middle school and middle school students to the high school. No problems there. The script does several things:

    1. imports users from a csv file
    2. create user
    3. adds user to the correct groups
    4. creates home directory
    5. sets home directory rights.

    1-4 are working as always. The only thing I can come across that is "different" is we added a new District Instructional Tech person and gave her rights to see the existing student home directories. I guess it is possible that over wrote something. I'm sure it is something stupid and simple I ma just over looking.

    Thanks again for all your suggestions.

  8. #8
    Marshall_IT's Avatar
    Join Date
    Jul 2011
    Location
    Leeds
    Posts
    509
    Thank Post
    77
    Thanked 63 Times in 54 Posts
    Blog Entries
    1
    Rep Power
    19
    Check to make sure permissions have not been changed at the top level as this filters down through inheritance.

  9. #9

    Join Date
    Jan 2011
    Location
    Anderson
    Posts
    35
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    I appreciate all the suggestions.

    I have checked everything I can think of. Even tried doing this as domain admin rather than my username. Nothing makes a difference. I have no idea what changed but obviously something has. I'm at a stand still. I'd love to be able to use my script but....

    Thanks again for all the help and suggestions.

SHARE:
+ Post New Thread

Similar Threads

  1. IE7 Script Error
    By BassTech in forum Windows
    Replies: 16
    Last Post: 5th February 2010, 12:02 PM
  2. Powershell script to list printers with WPK
    By fawkers in forum Scripts
    Replies: 1
    Last Post: 17th November 2009, 09:55 AM
  3. Director Player Script Error
    By laserblazer in forum Windows
    Replies: 0
    Last Post: 29th September 2009, 08:44 AM
  4. Replies: 0
    Last Post: 24th January 2008, 02:58 PM
  5. Printers logon script error messages
    By indie in forum Windows
    Replies: 1
    Last Post: 14th September 2007, 11:34 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •