Reputation: 1454
When I run this code in powershell I get an error that A parameter cannot be found that matches parameter name 'directory'? Any idea what is wrong? Thank you
$Output = @()
$DirList = GCI \\server\share -directory | %{$_.FullName; GCI $_ -Directory|select -expandproperty FullName}
ForEach($Dir in $DirList){
$ACLs=@()
(get-acl $Dir).accesstostring.split("`n")|?{$_ -match "^(.+?admin(istrators|141))\s+?(\w+?)\s+?(.+)$"}|%{
$ACLs+=[PSCUSTOMOBJECT]@{Group=$Matches[1];Type=$Matches[2];Access=$Matches[3]}
}
ForEach($ACL in $ACLs){
if($Members){Remove-Variable Members}
$Members = Get-ADGroupMember $ACL.Group -ErrorAction SilentlyContinue|%{[string]$_.SamAccountName}
$Output += "$Dir $($ACL.Group) $($ACL.Access) $($Members -join ",")"
}
}
Upvotes: 2
Views: 26581
Reputation: 2772
Problem is in $DirList = GCI \\server\share -directory
and GCI $_ -Directory
The Get-ChildItem cmdlet does not support a -directory
parameter (EDIT: before version 3).
It looks like you are trying to get and process every top level directory entry on a network file share. This can be achieved as follows:
Get-ChildItem -path \\server\share | Where-Object { $_.PSIsContainer } | ForEach-Object { Write-host $_.FullName # processing code here }
Upvotes: 3
Reputation:
You need PowerShell version 3.0 at a minimum to support the -Directory
parameter on the Get-ChildItem
cmdlet. If you're on Windows 7, you can upgrade to Windows Management Framework Core 4.0 after installing the Microsoft .NET Framework 4.5.1.
Upvotes: 3