troubleshooting Question

Cannot modify permissions on files

Avatar of carbonbase
carbonbaseFlag for United Kingdom of Great Britain and Northern Ireland asked on
2 Comments1 Solution77 ViewsLast Modified:
Hi I have some Powershell code which in the past I've used to modify permissions on files and folders.  After a number of months I've run the code against some data I've migrated from a decommissioned NAS device.  The problem I'm having is that only permissions on folders have changed, but I want to change both the folder and file permissions.  I'm able to change permissions on folders, even ones I don't own but I cannot change permissions on files.

$rights = [System.Security.AccessControl.FileSystemRights]::Modify
$inheritance = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit,ObjectInherit"
$propagation = [System.Security.AccessControl.PropagationFlags]::None
$allowdeny = [System.Security.AccessControl.AccessControlType]::Allow


# Customize the domain name
$myDomain = ""
$adminUserName = "IT Dept"
[string]$ErrorLog = 'C:\Temp\Permission_Errors.txt'
$StartFolder = 'V:\Adobe'

$Account = [System.Security.Principal.NTAccount]"$myDomain\$adminUserName"
& cmd.exe /c "echo \\?\$($StartFolder)&dir /s /a:d /b `"\\?\$($StartFolder)`"" | ForEach `
	$folder = $_.SubString(4)
	Try {
		$Acl = Get-Acl -LiteralPath $folder -ErrorAction Stop
		$CurrentAccess = @($Acl.Access | Select-Object -ExpandProperty IdentityReference)
		If ($CurrentAccess -Contains $Account)    
			Write-Host  "Skipping folder.  This user account already has permission: $Account"
			Write-Host  "To the folder: $($folder)"
			$Ace = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList $Account, $rights, $inheritance, $propagation, $allowdeny
			Write-Host "Setting permission for folder: $($folder)" -ForegroundColor Yellow
			Set-Acl -LiteralPath $folder -AclObject $Acl -ErrorAction Stop
		Write-Warning "Problem setting permission to folder:  $($folder)"
		Write-Warning "The following error occurred: $error " 
		"Problem getting/setting permission to folder: '$($folder)'.  The Error encountered was: '$error'" | Out-File $ErrorLog -Append

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros