Powershell About File System

Posted The Scented Path

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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[email protected]()
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[email protected]()
#将结果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 
 

 

以上是关于Powershell About File System的主要内容,如果未能解决你的问题,请参考以下文章

Powershell About Active Directory Group Membership of a domain user

question about import google file

about_Execution_Policies

powershell 用于更新xml file.ps1的Powershell脚本

[powershell]Use powershell to get file hash / 使用powershell获取文件哈希值

在 Powershell 中将文件重命名为小写