Link to home
Start Free TrialLog in
Avatar of creative555
creative555

asked on

help to improve the scrip by adding params

Help me to improve the script by adding param or variables or function. Or perhaps it is OK like that.


So, I have this script which is working. However, I would like to make it more professional and add some param or function to it. So, i tried adding param for group that I want to filter by "TESTSOURCE\DOMAIN Users". As soon as I add param, it doesn't work. Please let me know.

  param(
    [String]$Group='Domain Users',
    [String]$Directory='c:\install'
)

Get-ChildItem $directory -Recurse | ?{ $_.PsIsContainer } | %{
$Path = $_.FullName
 
 (Get-Acl $Path).Access | Select-Object `
    @{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
    InheritanceFlags, PropagationFlags, FileSystemRights, IsInherited| ?{$_.identityreference.value.ToString() -like $Group}
} | Export-CSV "PermissionsDomainUsers9b.csv"

i get an error:

Get-ChildItem : Access to the path 'C:\Windows\System32\LogFiles\WMI\RtBackup' is denied.
At line:7 char:1
+ Get-ChildItem $directory -Recurse | ?{ $_.PsIsContainer } | %{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Windows\Syst...es\WMI\RtBackup:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
ASKER CERTIFIED SOLUTION
Avatar of rastoi
rastoi
Flag of Slovakia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of creative555
creative555

ASKER

Brilliant!! YEs. I mistyped the directory name and that is why it was failing....thanks a lot!!!