zoukankan      html  css  js  c++  java
  • 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:psfilerightinfo_$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:PSShareinfo_$CurrentDate.csv -Encoding UTF8 -NoTypeInformation 
     
  • 相关阅读:
    在Docker中启动Nacos-Server
    maven配置阿里云公共仓库
    Centos7动态IP改静态后SSH很慢
    Vue+NodeJS的跨域请求Session不同
    一款非常简洁漂亮方便调用的jQuery前端分页
    springmvc后台接收List参数的几种办法
    net use命令详解(转)
    c#开发windows服务
    c# base64转字符串
    关于web api 验证
  • 原文地址:https://www.cnblogs.com/thescentedpath/p/powershellfile.html
Copyright © 2011-2022 走看看