zoukankan      html  css  js  c++  java
  • Grant-Permission.ps1

    Grant-Permission.ps1

    Download the EXE version of SetACL 3.0.6 for 32-bit and 64-bit Windows. Put setacl.exe at the same location with the script.

    function Grant-Permission
    {
        [CmdletBinding(SupportsShouldProcess=$true)]
        param(
            [Parameter()]
            [string]$ComputerName = $env:computername,
            
            [Parameter(Mandatory=$true)]
            [string]$Path,
            
            [Parameter(Mandatory=$true)]
            [ValidateSet('file','reg','srv','prn','shr','wmi')]
            [string]$Type,
            
            [Parameter(Mandatory=$true)]
            [string]$Name,
            
            [Parameter(Mandatory=$true)]
            [string]$Permission,
            
            [Parameter()]
            [switch]$PassThru
        )
        
        Write-Verbose "Granting '$Name' $Permission permission on '$ComputerName'..."
        
        if(!(Test-Connection $ComputerName -Count 1 -Quiet))
        {
            Write-Error "Unable to connect '$ComputerName'. The network path not found."
            return
        }
        try
        {
            if(!$PSScriptRoot) { $PSScriptRoot = Split-Path (Get-Variable MyInvocation -Scope 1).Value.MyCommand.Path }
            Set-Alias setacl "$PSScriptRootsetacl.exe"
            if($ComputerName -ne $env:computername) { $fullPath = "\$ComputerName$Path" } else { $fullPath = $Path }
            $result = Invoke-Expression "setacl -on `"$fullPath`" -ot $Type -actn ace -ace `"n:$Name;p:$Permission`""
            if($result -match "error") {
                Write-Error ($result -join "`n")
                return
            }
            Write-Verbose ($result -join "`n")
            Write-Verbose "'$Name' has been granted $Permission permission on '$ComputerName'."
            
            if($Passthru)
            {
                $pso = New-Object PSObject -Property @{
                     ComputerName = $ComputerName.ToUpper()
                     Path = $Path
                     Type = $Type
                     Name = $Name
                     Permission = $Permission
                }
                $pso.PSTypeNames.Clear()
                $pso.PSTypeNames.Add('MKServerBuilder.ACL')
                $pso
            }
        }
        catch
        {
            $_
        }
    }
  • 相关阅读:
    Scrapy shell调试返回403错误
    android 获取 imei号码
    查找目录下的所有文件中是否含有某个字符串
    自动生成和配置ES的安全证书
    docker构建本地私有镜像
    ELK容器化部署
    Rancher使用基础知识1
    jenkins自动打包部署流水线
    ansible管理windows主机
    jenkins集成gitlab自动构建打包
  • 原文地址:https://www.cnblogs.com/edward2013/p/3536847.html
Copyright © 2011-2022 走看看