Powershell About File System

 

File System Rights

Get-Acl $sharepath | select -expand access | where { !$_.IsInherited -AND $_.filesystemrights -eq 'fullcontrol'}
 Get-Acl $sharepath | select -expand access | where {($_.identityreference -eq "everyone") -and ($_.InheritanceFlags -ne "None")}
$Result=@()
foreach($ComputerName in (Get-Content E:\fileserverlist.txt))
{
$Shareinfo=Get-WmiObject -ComputerName $computerName -Class win32_share | where { $_.type -eq 0 }
     $Shareinfo | %{
     $sharepath="\\" + $_.pscomputername + "\" +$_.Name   
$acls = Get-Acl $sharepath | select -expand access | where { !$_.IsInherited -AND $_.filesystemrights -eq 'fullcontrol'}
foreach ($acl in $acls)
{$user=$acl.identityreference
$username=$user -replace '^.*\\'
$right=$acl.filesystemrights
if($user -like 'Domain*')
{
$userinfo=get-aduser -identity $username -Properties department,enabled
$dep=$userinfo.department
$name=$userinfo.name
$userstatus=$userinfo.enabled
}
else
{
$dep='no'
$name=$username
}
$info=New-Object Psobject
$info |Add-Member -MemberType NoteProperty -Name Name -Value $user
$info |Add-Member -MemberType NoteProperty -Name Name -Value $name
$info |Add-Member -MemberType NoteProperty -Name status -Value $userstatus
$info |Add-Member -MemberType NoteProperty -Name dept-Value $dep
$info |Add-Member -MemberType NoteProperty -Name ritht -Value $right
$info |Add-Member -MemberType NoteProperty -Name path -Value $sharepath
$Result+=$info
}
}
  }  
  $CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('yyyy-MM-dd')
$Result |Export-Csv D:\ps\filerightinfo_$CurrentDate.csv -Encoding UTF8 -NoTypeInformation 
 

获取Share Folder
Get-WmiObject -ComputerName $computerName -Class win32_share | where { $_.type -eq 0 }
$Result=@()
#将结果G赋值E给一@个空A数组
foreach($ComputerName in (Get-Content E:\IP.txt))
    {
    $Pingy = Get-WmiObject Win32_PingStatus -f "Address='$ComputerName'" 
    #循¦`环ping txt文a档中?的ocomputername
    if($Pingy.StatusCode -eq 0)
        {
        $errorcount=$error.count
        $Shareinfo=Get-WmiObject -ComputerName $computerName -Class win32_share | where { $_.type -eq 0 }
        #如p果Gping得Óo通q,A获取Luservice
        if($Shareinfo)
            {
            $Shareinfo | %{
                $Resultinfo=New-Object PSobject
                $Resultinfo |Add-Member -MemberType NoteProperty -Name ipaddress -Value $ComputerName
                $Resultinfo |Add-Member -MemberType NoteProperty -Name Computername -Value $_.pscomputername
                $Resultinfo |Add-Member -MemberType NoteProperty -Name ShareName -Value $("\\" + $_.pscomputername + "\" +$_.Name)
                $Result+=$Resultinfo
                }
            }
        else{
            if($errorcount -eq $error.Count)
                {
                $Resultinfo=New-Object PSobject
                $Resultinfo |Add-Member -MemberType NoteProperty -Name ipaddress -Value $ComputerName 
                $Resultinfo |Add-Member -MemberType NoteProperty -Name Computername -Value $Shareinfo.pscomputername                
                $Resultinfo |Add-Member -MemberType NoteProperty -Name ShareName -Value "No Share"                
                $Result+=$Resultinfo
                }
                else
                    {
                    $Resultinfo=New-Object PSobject
                    $Resultinfo |Add-Member -MemberType NoteProperty -Name ipaddress -Value $ComputerName 
                    $Resultinfo |Add-Member -MemberType NoteProperty -Name Computername -Value $Shareinfo.pscomputername
                    $Resultinfo |Add-Member -MemberType NoteProperty -Name ShareName -Value "RPC error"
                    $Result+=$Resultinfo
                    }
                }
        }
    else
        {
        $Resultinfo=New-Object PSobject
        $Resultinfo |Add-Member -MemberType NoteProperty -Name ipaddress -Value $ComputerName 
        $Resultinfo |Add-Member -MemberType NoteProperty -Name Computername -Value $Shareinfo.pscomputername 
        $Resultinfo |Add-Member -MemberType NoteProperty -Name ShareName -Value "The Computer is Unaviable"
        $Result+=$Resultinfo
        }
    }
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('yyyy-MM-dd')
$Result |Export-Csv D:\PS\Shareinfo_$CurrentDate.csv -Encoding UTF8 -NoTypeInformation 
 

 

posted @ 2017-07-08 19:23  寻香径  阅读(269)  评论(0编辑  收藏  举报