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:\ins tall'
)
Get-ChildItem $directory -Recurse | ?{ $_.PsIsContainer } | %{
$Path = $_.FullName
(Get-Acl $Path).Access | Select-Object `
@{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
InheritanceFlags, PropagationFlags, FileSystemRights, IsInherited| ?{$_.identityreference.val ue.ToStrin g() -like $Group}
} | Export-CSV "PermissionsDomainUsers9b. csv"
i get an error:
Get-ChildItem : Access to the path 'C:\Windows\System32\LogFi les\WMI\Rt Backup' is denied.
At line:7 char:1
+ Get-ChildItem $directory -Recurse | ?{ $_.PsIsContainer } | %{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Windows\Syst...es\WMI\ RtBackup:S tring) [Get-ChildItem], UnauthorizedAccessExceptio n
+ FullyQualifiedErrorId : DirUnauthorizedAccessError ,Microsoft .PowerShel l.Commands .GetChildI temCommand
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:\ins
)
Get-ChildItem $directory -Recurse | ?{ $_.PsIsContainer } | %{
$Path = $_.FullName
(Get-Acl $Path).Access | Select-Object `
@{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
InheritanceFlags, PropagationFlags, FileSystemRights, IsInherited| ?{$_.identityreference.val
} | Export-CSV "PermissionsDomainUsers9b.
i get an error:
Get-ChildItem : Access to the path 'C:\Windows\System32\LogFi
At line:7 char:1
+ Get-ChildItem $directory -Recurse | ?{ $_.PsIsContainer } | %{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Windows\Syst...es\WMI\
+ FullyQualifiedErrorId : DirUnauthorizedAccessError
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER