Quantcast
Channel: Zohno Inc. » WMI
Viewing all articles
Browse latest Browse all 2

List Windows Server File Shares and permissions using Powershell

$
0
0

Courtesy of Zohno Inc, Please visit TechNet gallery to download the Z-Hire User Creation Tool.

This script will retrieve list of shares and it’s permissions from a remote computer or local computer. This is helpful when performing SOX audits to figure out who has what access to these shares. This script simply uses WMI get list of shares and its ACL information. Enjoy.

$remotecomputername="host1"
$shareslist = gwmi -computer $remotecomputername -Class win32_share | select -ExpandProperty Name
foreach ($shareinstance in $shareslist) {
$acl = $null
Write-Host $('-' * $shareinstance.Length)
$SecuritySettings = Get-WMIObject $remotecomputername -Class Win32_LogicalShareSecuritySetting -Filter "name='$Shareinstance'"
$SecurityDescriptor = $SecuritySettings.GetSecurityDescriptor().Descriptor
foreach($ace in $SecurityDescriptor.DACL){
$UserName = $ace.Trustee.Name
If ($ace.Trustee.Domain -ne $Null) {$UserName = "$($ace.Trustee.Domain)\$UserName"}
If ($ace.Trustee.Name -eq $Null) {$UserName = $ace.Trustee.SIDString }
[Array]$ACL += New-Object Security.AccessControl.FileSystemAccessRule($UserName, $ace.AccessMask, $ace.AceType)
}
$ACL
Write-Host $('=' * 50)
}


Viewing all articles
Browse latest Browse all 2

Trending Articles