Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Write a .net and powershell script to manipulate folder and acl.
- Here's an example .NET and PowerShell script to manipulate folder and ACL:
- .NET:
- csharp
- using System;
- using System.IO;
- using System.Security.AccessControl;
- class Program
- {
- static void Main(string[] args)
- {
- string folderPath = @"C:\example\folder";
- string user = "DOMAIN\username";
- FileSystemAccessRule rule = new FileSystemAccessRule(user, FileSystemRights.FullControl, AccessControlType.Allow);
- // Create the folder if it doesn't exist
- if (!Directory.Exists(folderPath))
- {
- Directory.CreateDirectory(folderPath);
- }
- // Get the folder's ACL
- DirectorySecurity security = Directory.GetAccessControl(folderPath);
- // Add the new rule to the ACL
- security.AddAccessRule(rule);
- // Set the folder's new ACL
- Directory.SetAccessControl(folderPath, security);
- }
- }
- PowerShell:
- powershell
- $folderPath = "C:\example\folder"
- $user = "DOMAIN\username"
- $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($user, "FullControl", "Allow")
- # Create the folder if it doesn't exist
- if (!(Test-Path $folderPath))
- {
- New-Item -ItemType Directory -Path $folderPath
- }
- # Get the folder's ACL
- $security = Get-Acl $folderPath
- # Add the new rule to the ACL
- $security.AddAccessRule($rule)
- # Set the folder's new ACL
- Set-Acl $folderPath $security
- Both scripts create a folder at `C:\example\folder` if it doesn't exist, and add a new ACL rule to give the user `DOMAIN\username` full control over the folder. Share
- Start chat...
- chatgptweb.org realistic unlimited experience of AI.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement