This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hi All
A customer of ours has requested an export of all the file shares on all thier servers along with the permissions of all the file shares.
They are planning to move to cloud storage at some stage and want an export of this data from thier servers.
I made a script that takes in some UNC Paths and exports the folder name, and permissions of said folders and exports them to a CSV
Here is the script im using
$ShareNames = @(
"\\?\UNC\fs-hd-01\Common",
"\\?\UNC\fs-hd-01\Information Services",
"\\?\UNC\fs-hd-01\Lean Supply Chain",
"\\?\UNC\fs-hd-01\Logon Audit",
"\\?\UNC\fs-hd-01\Machine Learning",
"\\?\UNC\fs-hd-01\Operational",
"\\?\UNC\fs-hd-01\SD",
"\\?\UNC\fs-hd-01\Search DB",
"\\?\UNC\fs-hd-01\Software Library",
"\\?\UNC\fs-hd-01\Supplier Sales Reports 18.1.2",
"\\?\UNC\fs-hd-01\TenderMax",
"\\?\UNC\fs-hd-01\Scans",
"\\?\UNC\fs-hd-01\UHYHN"
# Add more share names as needed
)
$Results = foreach ($ShareName in $ShareNames) {
$AllFolders = Get-ChildItem -LiteralPath $ShareName -Directory -Force -Recurse
foreach ($Folder in $AllFolders) {
$Acl = Get-Acl -LiteralPath $Folder.PSPath
foreach ($Access in $Acl.Access) {
if ($Access.IsInherited -eq $false -and
$Access.IdentityReference.Value -notin "BUILTIN\Administrators", "CREATOR OWNER", "NT AUTHORITY\SYSTEM", "BUILTIN\users") {
[PSCustomObject]@{
'FolderName' = $Folder.FullName
'AD Group' = $Access.IdentityReference
'Permissions' = $Access.FileSystemRights
}
}
}
}
}
$ExportPath = "C:\temp\permissions.csv"
$Results | Export-Csv -Path $ExportPath -NoTypeInformation -Force
The server im running this on has a 2tb drive with hundreds of thousands of folders. I let the script run overnight and got an excel spreadsheet that error'ed out with a row limit
Does anyone know of a more efficient way of doing this? How can I make my life easier? I have 50 servers that i need to check through
Would it be better to run this on the servers directly using the exact directory rather than the UNC Paths?
Thanks
Subreddit
Post Details
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/PowerShell/...