Write a Powershell script. iterate over a windows filesystem. Collect fullnames. Iterate…
- User
Write a Powershell script. iterate over a windows filesystem. Collect fullnames. Iterate over the SIDs for each folder. Write Fullname and SID to a CSV.
- Assistant
Sure, here's a PowerShell script that iterates over a Windows filesystem, collects fullnames, iterates over the SIDs for each folder, and writes the fullname and SID to a CSV file:
powershell# Set the path to the root directory you want to start iterating from $rootPath = "C:\Users\" # Create an empty array to store the results $results = @() # Iterate over each item in the root directory and its subdirectories Get-ChildItem -Path $rootPath -Recurse | ForEach-Object { # Check if the item is a directory if($_.PSIsContainer) { # Get the full name of the directory $fullname = $_.FullName # Get the security descriptor for the directory $securityDescriptor = Get-Acl $fullname # Iterate over the access rules in the security descriptor foreach($accessRule in $securityDescriptor.Access) { # Check if the access rule is for a user or group if($accessRule.IdentityReference.Value -match "^S-1-5-21-") { # Add the fullname and SID to the results array $results += [PSCustomObject]@{ Fullname = $fullname SID = $accessRule.IdentityReference.Value } } } } } # Write the results array to a CSV file $results | Export-Csv -Path "C:\output.csv" -NoTypeInformationThis script starts iterating from the root directory
C:\Users\, but you can change the$rootPathvariable to start from any other directory. The script then usesGet-ChildItemto recursively iterate over each item in the directory and its subdirectories. For each item, the script checks if it's a directory, gets the full name of the directory using theFullNameproperty, and gets the security descriptor for the directory using the cmdlet. - User
that's good, but don't check to see if the access rule is for a user or group. Also, add a third column that shows the actual sid rather than the string value.
- Assistant
Sure, here's an updated PowerShell script that iterates over a Windows filesystem, collects fullnames, iterates over the SIDs for each folder, and writes the fullname, SID, and actual SID value to a CSV file:
powershell - User
Using Powershell, for each folder on a filesystem, identify whether the only reference to the folder is from a user or group's SIDHistory, instead of their SID.
- Assistant
- User
Good, but instead of checking Builtin Administrators, check against SIDHistory of every user and group in the domain.
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.