“无法获取“共享名称”的权限| win2008r2文件服务器

时间:2020-05-07 12:17:24

标签: powershell

所以,一个朋友和我写了一个脚本,以便我们可以在文件服务器上获取有关共享的一些信息,但是我不断遇到有关共享的错误,我是域管理员,所以我认为问题不在于我的权限。

这是脚本:

$MyPath     = "C:\File Share Info\Shares"
$shares     = gwmi -Class win32_share -ComputerName $computer #| select -ExpandProperty Name
$AllObjects = @()

foreach ($share in $shares) {
$acl = $null
$ShareName = $share.Name
$ShareCaption = $Share.Caption
if ($ShareName -notlike "*$*"){
    $objShareSec = Get-WMIObject -Class Win32_LogicalShareSecuritySetting -Filter "name='$ShareName'"  
    #-ComputerName $computer
    try {
        $SD = $objShareSec.GetSecurityDescriptor().Descriptor

        foreach($ace in $SD.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)
            $Identity = $ACL[0].IdentityReference.Value

            $myObject = New-Object System.Object
            $myObject | Add-Member -type NoteProperty -name ShareAccessType -Value $ACL[0].AccessControlType
            $myObject | Add-Member -type NoteProperty -name Identity -Value $Identity
            $myObject | Add-Member -type NoteProperty -name ShareRights -Value $ACL[0].FileSystemRights
            $myObject | Add-Member -type NoteProperty -name SharePath -Value $Share.Path
            $myObject | Add-Member -type NoteProperty -name ShareName -Value $Share.Name
            $myObject | select ShareName, Identity, ShareRights, SharePath, ShareAccessType | Export-Csv "$MyPath\permissions.csv" -Append -Encoding Unicode #-NoTypeInformation -Delimiter "`t"

        } 
    } 
    catch
        { Write-Host "Unable to obtain permissions for `"$ShareName`""; $share.Name | Out-File "$MyPath\Failed.txt" -Append}
}
  } 

0 个答案:

没有答案