The files in the folder have different NTFS permissions.
I want to move files to different folders for each permission with Powershell or C#.
Do you have good code?
The files in the folder have different NTFS permissions.
I want to move files to different folders for each permission with Powershell or C#.
Do you have good code?
Hi,
Please check to see if this works for you.
$source = "C:\temp\source"
$destination = "C:\temp\destination"
$files = @()
Get-ChildItem -Path $source -File -Recurse | ForEach-Object {
$files += [pscustomobject]@{
sddl = (Get-Acl $_.FullName).GetSecurityDescriptorSddlForm('All')
path = $_.FullName
}
}
$folders = @{}
$counter = 0
$files |Select-Object -ExpandProperty sddl -Unique | ForEach-Object {
$folders.add($_,"$destination\folder$counter")
$counter ++
}
$files | ForEach-Object {
if(-not (Test-Path -Path $folders.($_.sddl))){
New-Item -Path $folders.($_.sddl) -ItemType Directory
}
Move-Item -Path $_.path -Destination $folders.($_.sddl)
}
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
13 people are following this question.