[英]Powershell script for
我有 Windows Server 2016 Datacenter(64 位)作為文件服務器(包含幾個共享文件夾和子文件夾)。
我想制作一個列表或導出用戶文件夾結構以及權限(讀取、修改、完整......等)
我嘗試使用下面的 PS 腳本,但我收到一條錯誤消息,我在腳本之后提到過。
電源外殼
$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"
錯誤:
dir :拒絕訪問路徑“E:\\Project Folders**Folder Path**\\New folder”。 在 C:\\Users\\Administrator\\Documents\\PS Script**File Name**.ps1:1 char:15 + ... oldPath = dir -Directory -Path "E:\\Project Folders**Folder Name**" -再...+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (E:\\Project Fold...ngar\\New folder:String) [Get-Child Item], UnauthorizedAccessException +fullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell。 Commands.GetChildItemCommand
請幫幫我!
提前致謝
正如其他評論所指出的那樣。
這不是 PowerShell 錯誤/問題,而是權限問題。 如果你說你在 Windows 文件夾樹上做了這個用例,同樣的事情可能/將會發生。
既然你知道這會發生,要么修復你正在處理的樹上的權限,要么這樣做。
Get-ChildItem -Directory -Path 'C:\Windows\System32' -Recurse -ErrorAction SilentlyContinue
或者如果您只想在路徑失敗時停止。
# 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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.