Code snippet below will create a folder using the old conventional "md" or make a directory DOS command, which is equivalent to "mkdir" in Linux world.
Folder permissions or security settings will be set using ICACLS.exe which is also a command prompt.
PowerShell of course, can do this job. Using Set-ACL cmdlet and Get-ACL cmdlet will view the security permissions settings.
Example below will create a folder "xtxtFolder" and Icacls will remove the inherited permissions and grant full access to xRepoUser.
To find out more syntax on Icacls, type on command prompt "Icacls /?", don't include quotation marks.
Code below can be set via Task Scheduler and run at a specified time, when the folder is needed and has to be ready.
===================================
#Create Folder
$xFolder = {md d:\xtxtFolder}
Invoke-Command $xFolder
#set Folder Permissions
#In order for the Permission to be set accordingly
#run the script with aprropriate admin credentials
$xPermissions = {"Icacls d:\xtxtFolder /inheritance:r /grant:r xRepoUser:(OI)(CI)(F)"}
Invoke-Command $xPermissions
===================================
To deny access to a user on a folder, using ICACLS command:
====================================
#Folder Path
$xFolder = {d:\xtxtFolder}
#set Folder Permissions
#In order for the Permission to be set accordingly
#run the script with aprropriate admin credentials
$xPermissions = {"Icacls d:\xtxtFolder /deny xRepoUser:(OI)(CI)(F) /T /C "}
Invoke-Command $xPermissions
===========================================
ICACLS will set deny permission for the user specified.
To verify the security permissions type this PowerShell command:
Get-acl d:\xtxtFolder | Format-List
Check this link from Technet and also this link that describes on how to set Security descriptors and shell permissions. Evaluate which one is simple and easy to use, Icacls or PowerShell method.
If PowerShell is used to set the security rights need to use the Set-ACL cmdlet, while using the ICACLS is quite straight forward. But i'm not sure whether PowerShell will process faster.
Cheers!! Just a simple code snippet..
Comments
Post a Comment