Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6738555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:22:58+00:00 2026-05-26T11:22:58+00:00

I am stumped! Here is what I need to do. We have migrated to

  • 0

I am stumped!

Here is what I need to do. We have migrated to a new domain, I basically need a script that we can run on a server that will re-curse all directories and files looking at the ACL’s for each. It will search the ACL for OLDDOMAIN\USER etc. if found change the ACL to NEWDOMAIN\USER but maintain all the permissions

Here is what I have so far

$access = ""
$accessarray = @()
$filesarray = @()
$permarray = @()
$filesarray = Get-ChildItem C:\Users -Recurse
ForEach($path in $filesarray) {
  $pathcheck = $path.fullname
  $access = get-acl $pathcheck
  $accessarray = $access.AccessToString.Split(",")

  foreach ($item in $accessarray) {
    if ($item -match "OLDDOMAIN") {
      Write-Host $pathcheck
      Write-Host $item
      $item = $item -replace ("OLDDOMAIN","NEWDOMAIN")
      $permarray = $item.split(” “) | where-object {$_ -ne ”“}

      foreach($perm in $permarray) {
        $ar = New-Object system.security.accesscontrol.filesystemaccessrule $perm
        $acl.SetAccessRule($ar)
        $acl | Set-Acl $pathcheck
      }
    }
  }
}

It works kind of, but the problem is that when it goes to reapply the permissions the array is not in the correct order and it fails at the set-acl command

Any ideas? Pulling my hair out here 😛

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:22:59+00:00Added an answer on May 26, 2026 at 11:22 am

    $ar = New-Object system.security.accesscontrol.filesystemaccessrule $perm

    The constructor for FileSystemAccessRule takes 3 arguments, and after all your splitting and foreach, $perm will have only one argument and that construction itself will fail.

    Avoid the splits etc. Powershell provides you objects. Operate on them. Don’t get strings, then split etc.

    You can do what you want with something like this:

    gci c:\users -recurse | %{
        $acl = get-acl $_.fullname
    
        $acl.Access | ?{$_.IdentityReference.Value.StartsWith("OLDDOMAIN")} | %{
    
            $identity = $_.IdentityReference.Value -replace "OLDDOMAIN", "NEWDOMAIN"
            $permission = $identity,$_.FileSystemRights,$_.AccessControlType
            $ar = New-Object system.security.accesscontrol.filesystemaccessrule $permission
            $acl.SetAccessRule($ar)
    
        }
    
        $acl | set-acl $_.fullname
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stumped here. I have an observable collection that holds business objects. I have
Okay, I'm stumped here. I have a control that is comprised of a table.
I'm completely stumped on this one. I have three different lists that need to
I have an application I am working on that will need the use of
I am completely stumped. I have a program that pulls information stored in a
New to magento here, I have figured out how to use my local.xml to
Okay, I am stumped on this one and need some quick help. I have
I am in need of a regular expression that I can use to examine
OK, I am stumped. I have an HTML table that is within a fixed
I am kind of stumped here and have been trying to figure this out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.