четверг, 31 декабря 2020 г.

Define permissions with SubInAcl (PowerShell script with Menu)

   cls

   # SubInACL #

#==PARAMETERS==

$Tool1="subinacl"

$UpDirOwner="MyDomain\Domain Admins"

$SubDirOwner="MyDomain\Domain Admins"

$UpDirUser="MyDomain\User"

$SubDirUser="MyDomain\User"

$UpDir="\\X.X.X.X\PSTs\" # use with /file parameter

$SubDir=-join($UpDir+"\*") # use with /subdirectories parameter

$errorlog="C:\temp\errorlog.txt"

$outputlog="C:\temp\outputlog.txt"

# ==OPTIONAL PARAMETERS==

# MD $UpDir # If you want to create UpDir you need to remove # sign from the beginnig of this line...

# ==OWNERSHIP==

& $Tool1 /errorlog=$errorlog /outputlog=$outputlog /file $UpDir /setowner=$UpDirOwner

ii $errorlog

& $Tool1 /errorlog=$errorlog /outputlog=$outputlog /subdirectories $SubDir /setowner=$SubDirOwner

ii $errorlog

#==PERMISSIONS==#

   $FullControl = "F"

   $Change = "C"

   $ReadeXecute = "E"

#============#============#

DO

{

$menu=@"

1. Full Control $FullControl; 

2. Change/Modify $Change; 

3. Read eXecute $ReadeXecute; 

Select a Permission by its number

"@

#============#============#

#Clear-Host

Write-Host ""

Write-Host "=Permission Menu=" -ForegroundColor Green

Write-Host ""

$Selection = Read-Host $Menu

#============#============#

$a = "N"

Switch ($Selection) { #Begin Switch

"1"{

    $FullControl

    & $Tool1 /file $UpDir /grant=$UpDirUser=$FullControl

    & $Tool1 /subdirectories $SubDir /grant=$SubDirUser=$FullControl

    Write-Host User $UpDirUser granted FullControl permissions on $UpDir folder and its subfolders

    $a = "Y"

    }

"2" {

    $Change

    & $Tool1 /file $UpDir /revoke=$UpDirUser

    & $Tool1 /file $UpDir /grant=$UpDirUser=$Change

    & $Tool1 /subdirectories $SubDir /revoke=$SubDirUser

    & $Tool1 /subdirectories $SubDir /grant=$SubDirUser=$Change

    Write-Host User $UpDirUser granted Change/Modify permissions on $UpDir folder and its subfolders

    $a = "Y"

    }

"3" {

    $ReadeXecute

    & $Tool1 /file $UpDir /revoke=$UpDirUser

    & $Tool1/file $UpDir /grant=$UpDirUser=$ReadeXecute

    & $Tool1 /subdirectories $SubDir /revoke=$SubDirUser

    & $Tool1 /subdirectories $SubDir /grant=$SubDirUser=$ReadeXecute

    Write-Host User $UpDirUser granted ReadeXecute permissions on $UpDir folder and its subfolders

    $a = "Y"

    }

    default {

    Write-Host "I don't understand what do you want to do." -ForegroundColor Yellow

}

} #end switch

}

UNTIL ($a -eq "Y")

# CHECK PERMISSIONS

& $Tool1 /file $UpDir

& $Tool1 /subdirectories $SubDir

ii $UpDir


Комментариев нет:

Отправить комментарий