Reputation: 1
I want to extract a folder and its sub folders permission details.
My server is Windows 2008, I use Windows PowerShell script but getting below error.
Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'. At line:1 char:5 + dir -Directory -Path "H:\RMSRE7\RMS1" -Recurse -Force + ~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
PowerShell script:
$FolderPath = dir -Directory -Path "\\H:\RMSRE7" -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 "D:\Public\RE7_FolderPermissions.csv"
Upvotes: 0
Views: 3177
Reputation: 200453
In PowerShell v2 (which is what you seem to be using) the Get-ChildItem
cmdlet doesn't have a parameter -Directory
. That was introduced with PowerShell v3.
If you want to restrict the results of Get-ChildItem
to directories you need to use a Where-Object
filter prior to PowerShell v3, e.g.:
$FolderPath = Get-ChildItem -Path "\\H:\RMSRE7" -Recurse -Force |
Where-Object { $_.PSIsContainer }
The [ordered]
type accelerator also isn't available prior to PowerShell v3, so you need to remove it from your code.
$Properties = [ordered]@{
'FolderName' = $Folder.FullName;
'AD Group or User' = $Access.IdentityReference;
'Permissions' = $Access.FileSystemRights;
'Inherited' = $Access.IsInherited
}
If you want to ensure a particular order of fields in the output CSV you can pipe the data through Select-Object
before the export. And you may want to add the parameter -NoType
to Export-Csv
to avoid the object type comment at the beginning of the output file.
$Report |
Select-Object FolderName, 'AD Group or User', Permissions, Inherited |
Export-Csv -Path "D:\Public\RE7_FolderPermissions.csv" -NoType
Upvotes: 1