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
        {
            $_
        }
    }
  • 相关阅读:
    Hibernate的入门Curd用法
    使用Struts2实现图片上传和拦截器
    Layui连接mysql操作CRUD案例
    Struts2连接Mysql的Crud使用
    Struts2中OGNL表达式的用法
    Struts2简介、初步使用
    Maven配置、使用
    Web前后端分离开发(CRUD)及其演变概括
    堆的建立、调整、删除、插入
    set(集合)的使用方法
  • 原文地址:https://www.cnblogs.com/edward2013/p/3536847.html
Copyright © 2011-2022 走看看