Avatar of creative555
creative555
 asked on

Help with Powershell script to get a report of only builtin groups

Hello,
I need help with this script.

I need to make this script to only get a report of BUILTIN groups like Domain Users, Administrators, Domain Admins because we don't migrate them. The builtin groups look like this “Builtin\<AccountName>”

thank you so much. Currently, the following gets all the groups.


# Include only folders from the root path
Get-ChildItem "C:\installs" -Recurse | ?{ $_.PsIsContainer } | %{
  $Path = $_.FullName

  (Get-Acl $Path).Access | Select-Object `
    @{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
    InheritanceFlags, PropagationFlags, FileSystemRights, IsInherited
} | Export-CSV "Permissions.csv"
PowershellScripting Languages

Avatar of undefined
Last Comment
creative555

8/22/2022 - Mon
rastoi

script you populated shows NTFS permisions on directories and has nothing to do with shares you mention in subject.
So what do you need ?
creative555

ASKER
oh I am sorry. Inventory of NTFS permissions where builtin groups have access.
ASKER CERTIFIED SOLUTION
rastoi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
creative555

ASKER
what does "?" mean? I can't find it online..


I get an error: An empty pipe element is not allowed.



PS C:\scripts> Get-ChildItem "C:\installs" -Recurse | ?{ $_.PsIsContainer } | %{
 $Path = $_.FullName
 
 (Get-Acl $Path).Access | Select-Object `
    @{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
    InheritanceFlags, PropagationFlags, FileSystemRights, IsInherited
    | ? {$_.identityreference.value -like "BUILTIN*"} }
At line:7 char:5
+     | ? {$_.identityreference.value -like "BUILTIN*"} }
+     ~
An empty pipe element is not allowed.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : EmptyPipeElement
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
rastoi

'?' is alias for where-object commandlet
I assume it hits folder with no acess to or corrupted descriptor. Try to add '-error silent' after closing curly bracket and run again
creative555

ASKER
yes. this works!! I will give you points. Should I put parameters for TESTTARGET\domain users?


Get-ChildItem "C:\installs" -Recurse | ?{ $_.PsIsContainer } | %{
 $Path = $_.FullName
 
 (Get-Acl $Path).Access | Select-Object `
    @{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
    InheritanceFlags, PropagationFlags, FileSystemRights, IsInherited| ?{$_.identityreference.value.ToString() -like "TESTTARGET\Domain Users"}
} | Export-CSV "PermissionsDomainUsers8.csv"
creative555

ASKER
I tried to put Domain Users in the param but it doens't work...the output file is empty and it doens't just get c:\install directory. It is doing other directory


    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 am getting this 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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
rastoi

those are runtime permission errors, listed one is that running account does not have access to C:\Windows\System32\LogFiles\WMI\RtBackup'  
.tostring() you added makes no sense, "value" is string type. Where the trouble is -like needs asterix convention for match
I suggest this:
 [String]$Group='*Domain Users',

on my local filestem, "Users" produces no output, but "*users" lists properly
creative555

ASKER
but it shouldn't be looking at this directory. It should be looking at c:\installs.
C:\Windows\System32\LogFiles\WMI\RtBackup'  

this script still is giving me an error about this directory. It works fine if I remove param ()
Also i tried to put just two variables on top and as soon as I put them, it breaks it.

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



Get-ChildItem -path $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 "PermissionsDomainUsers3.csv"



Error:
Get-ChildItem : Access to the path 'C:\Windows\System32\LogFiles\WMI\RtBackup' is denied.
At C:\scripts\Get-NTFSPermissionsBuiltinWithParams1b.ps1:8 char:1
+ Get-ChildItem -path $directory -Recurse | ?{ $_.PsIsContainer } | %{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Windows\Syst...es\WMI\RtBackup:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand


this doesn't work either. Same error.

$Group = "Domain Users"
 $Directory ="c:\install"

Get-ChildItem -path $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 "PermissionsDomainUsers3.csv"



This works perfectly!! But I want to add param or at least variable on top.

Get-ChildItem "C:\installs" -Recurse | ?{ $_.PsIsContainer } | %{
 $Path = $_.FullName
 
 (Get-Acl $Path).Access | Select-Object `
    @{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
    InheritanceFlags, PropagationFlags, FileSystemRights, IsInherited| ?{$_.identityreference.value.ToString() -like "TESTTARGET\Domain Users"}
} | Export-CSV "PermissionsDomainUsers8.csv"
rastoi

params works, possibly source of your truoble is that you always fill target variable like "C:\install", while in version without parameters you use path with 's' at the end = "C:\installs
as c:\install  directory not exist, your path points to current active than you have feeling that it parse wrong place
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
creative555

ASKER
Thank you so much! I had mistyped c:\installs. Your script works!!!!