简体   繁体   中英

Powershell script for

I have Windows Server 2016 Datacenter (64 bit) as a File Server (contains several Shared folder & subfolders).

I want to make a list OR export user Folder Structure along with permissions ( Read, Modify, Full .. etc..)

I tried with below PS script but I am getting an error message with I have mentioned after the script.

Powershell

$FolderPath = dir -Directory -Path "E:\Project Folders\#Folder_Name" -Recurse -Force 
$Report = @() 
Foreach ($Folder in $FolderPath) {     
    $Acl = Get-Acl -Path $Folder.FullName     
    foreach ($Access in $acl.Access)
    {
        $Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD Group or User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
        $Report += New-Object -TypeName PSObject -Property $Properties
    }
} 
$Report | Export-Csv -path "C:\Folder Permissions\Folder Name.csv" 

Error:

dir : Access to the path 'E:\\Project Folders**Folder Path**\\New folder' is denied. At C:\\Users\\Administrator\\Documents\\PS Script**File Name**.ps1:1 char:15 + ... olderPath = dir -Directory -Path "E:\\Project Folders**Folder Name**" -Re ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (E:\\Project Fold...ngar\\New folder:String) [Get-Child Item], UnauthorizedAccessException + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

Please help me out!

Thanks in Advance

As noted by the other comments.

This is not a PowerShell error/issue, it is a permissions one. The same thing can/will happen if you say you did this use case on the Windows folder tree.

Since you know this will happen, either fix the permissions on the tree you are working on or do this.

Get-ChildItem -Directory -Path 'C:\Windows\System32' -Recurse -ErrorAction SilentlyContinue

or if you want to just stop when a path fails.

# Treat non-terminating erros as terminating
$RootFolderUnc = 'C:\Windows\System32'

Try {Get-ChildItem -Directory -Path $RootFolderUnc -Recurse -ErrorAction Stop}
Catch [System.UnauthorizedAccessException] 
{
    Write-Warning -Message "$env:USERNAME. You do not have permissions to view this path."
    $_.Exception.Message
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM