help with the script. Issue when trying to accept multiple values. How do I make it accept more than one value.

I need the script to accept more than one directory and group. Why doesn’t it accepts multiple values?? It doens't produce the report when I do this
[String[]



#DOES NOT WORK. I get empty report.

  param(
    [Parameter(Mandatory = $True)]
    [String[]$Group,
    [ValidateScript({Test-Path -Path $_})]
    [Parameter(Mandatory = $True)]
    [String[]$Directory
)


THE FOLLOWING works.

  param(
    [Parameter(Mandatory = $True)]
    [String]$Group,
    [ValidateScript({Test-Path -Path $_})]
    [Parameter(Mandatory = $True)]
    [String]$Directory
)
#Requires -Version 4


$DataToExport = @()
$Dirs = Get-ChildItem -Path $directory -Recurse -Directory

Foreach($dir in $Dirs)
{
    $Acls = (Get-Acl -Path $dir.FullName).Access

    Foreach($acl in $Acls)
    {
        If($acl.IdentityReference.Value.ToString() -like $Group)
        {
            $props = @{
                "Path" = $dir.FullName
                "IdentityReference" = $acl.IdentityReference.Value.ToString()
                "AccessControlType" = $acl.AccessControlType
                "InheritanceFlags" = $acl.InheritanceFlags
                "PropagationFlags" = $acl.PropagationFlags
                "FileSystemRights" = $acl.FileSystemRights
                "IsInherited" = $acl.IsInherited
            }
            $DataToExport += (New-Object psobject -Property $props)
        }
    }
}

$DataToExport | Export-Csv "PermissionsDomainUsers1.csv" -NoTypeInformation
creative555Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Your type needs to be [String[] - the closing square bracket is missing in your code.

For a path array your code works without further changes. But for groups you need to add another loop, as the like operator does only allow for a single search pattern.
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
This is how an improved script could look like:
param(
    [Parameter(Mandatory = $True)]
    [String[]] $Group,

    [ValidateScript({Test-Path -Path $_})]
    [Parameter(Mandatory = $True)]
    [String[]] $Directory
) 
#Requires -Version 4

Get-ChildItem -Path $directory -Recurse -Directory |
% {
  $dirName = $_.FullName
  $Acls = (Get-Acl $dirName).Access 
  $(
    foreach ($grp in $group)
    {
      $Acls | ? { $_.IdentityReference.Value.ToString() -like $grp }
    }
  ) |
  % {
    [PsCustomObject] @{
                "Path"              = $dirName
                "IdentityReference" = $_.IdentityReference.Value.ToString()
                "AccessControlType" = $_.AccessControlType
                "InheritanceFlags"  = $_.InheritanceFlags
                "PropagationFlags"  = $_.PropagationFlags
                "FileSystemRights"  = $_.FileSystemRights
                "IsInherited"       = $_.IsInherited
            }
  }
} | Export-Csv "PermissionsDomainUsers1.csv" -NoTypeInformation

Open in new window

It makes use of pipelining, which is the preferred processing method for PowerShell.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
creative555Author Commented:
Thank you so much!!! Great help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.