Add a function for allowing user access

This commit is contained in:
Manuel Thalmann 2024-08-09 15:56:16 +02:00
parent 92e4889417
commit 505ee2ad34
2 changed files with 30 additions and 11 deletions
scripts/Windows/Scripts

View file

@ -1,3 +1,6 @@
using namespace System.Security.AccessControl;
using namespace System.Security.Principal;
$null = New-Module {
$uacOption = "EnableLUA";
$systemPolicyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
@ -33,4 +36,29 @@ $null = New-Module {
function Disable-UAC {
& $uacSetter $false;
}
<#
.SYNOPSIS
Sets read/write permissions for users at the specified path.
.PARAMETER Path
The path to allow access to users.
#>
function Set-UserPermissions {
param(
[string] $Path
)
$acl = Get-Acl $Path;
$acl.AddAccessRule(
[FileSystemAccessRule]::new(
[SecurityIdentifier]::new([WellKnownSidType]::BuiltinUsersSid, $null),
[FileSystemRights]::FullControl,
[InheritanceFlags]::ObjectInherit -bor [InheritanceFlags]::ContainerInherit,
[PropagationFlags]::InheritOnly,
[AccessControlType]::Allow));
Set-Acl $Path $acl;
}
};