Set-Acl (Microsoft.PowerShell.Security) - PowerShell (2024)

  • Reference
Module:
Microsoft.PowerShell.Security

Changes the security descriptor of a specified item, such as a file or a registry key.

Syntax

Set-Acl [-Path] <String[]> [-AclObject] <Object> [-ClearCentralAccessPolicy] [-Passthru] [-Filter <String>] [-Include <String[]>] [-Exclude <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-Acl [-InputObject] <PSObject> [-AclObject] <Object> [-Passthru] [-Filter <String>] [-Include <String[]>] [-Exclude <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-Acl -LiteralPath <String[]> [-AclObject] <Object> [-ClearCentralAccessPolicy] [-Passthru] [-Filter <String>] [-Include <String[]>] [-Exclude <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

This cmdlet is only available on the Windows platform.

The Set-Acl cmdlet changes the security descriptor of a specified item, such as a file or aregistry key, to match the values in a security descriptor that you supply.

To use Set-Acl, use the Path or InputObject parameter to identify the item whose securitydescriptor you want to change. Then, use the AclObject or SecurityDescriptor parameters tosupply a security descriptor that has the values you want to apply. Set-Acl applies the securitydescriptor that is supplied. It uses the value of the AclObject parameter as a model and changesthe values in the item's security descriptor to match the values in the AclObject parameter.

Examples

Example 1: Copy a security descriptor from one file to another

$DogACL = Get-Acl -Path "C:\Dog.txt"Set-Acl -Path "C:\Cat.txt" -AclObject $DogACL

These commands copy the values from the security descriptor of the Dog.txt file to the securitydescriptor of the Cat.txt file. When the commands complete, the security descriptors of the Dog.txtand Cat.txt files are identical.

The first command uses the Get-Acl cmdlet to get the security descriptor of the Dog.txt file.The assignment operator (=) stores the security descriptor in the value of the $DogACL variable.

The second command uses Set-Acl to change the values in the ACL of Cat.txt to the values in$DogACL.

The value of the Path parameter is the path to the Cat.txt file. The value of the AclObjectparameter is the model ACL, in this case, the ACL of Dog.txt as saved in the $DogACL variable.

Example 2: Use the pipeline operator to pass a descriptor

Get-Acl -Path "C:\Dog.txt" | Set-Acl -Path "C:\Cat.txt"

This command is almost the same as the command in the previous example, except that it uses apipeline operator (|) to send the security descriptor from a Get-Acl command to a Set-Aclcommand.

The first command uses the Get-Acl cmdlet to get the security descriptor of the Dog.txt file. Thepipeline operator (|) passes an object that represents the Dog.txt security descriptor to theSet-Acl cmdlet.

The second command uses Set-Acl to apply the security descriptor of Dog.txt to Cat.txt.When the command completes, the ACLs of the Dog.txt and Cat.txt files are identical.

Example 3: Apply a security descriptor to multiple files

$NewAcl = Get-Acl File0.txtGet-ChildItem -Path "C:\temp" -Recurse -Include "*.txt" -Force | Set-Acl -AclObject $NewAcl

These commands apply the security descriptors in the File0.txt file to all text files in the C:\Tempdirectory and all of its subdirectories.

The first command gets the security descriptor of the File0.txt file in the current directory anduses the assignment operator (=) to store it in the $NewACL variable.

The first command in the pipeline uses the Get-ChildItem cmdlet to get all of the text files in theC:\Temp directory. The Recurse parameter extends the command to all subdirectories ofC:\temp. The Include parameter limits the files retrieved to those with the .txt file nameextension. The Force parameter gets hidden files, which would otherwise be excluded. (You cannotuse c:\temp\*.txt, because the Recurse parameter works on directories, not on files.)

The pipeline operator (|) sends the objects representing the retrieved files to the Set-Aclcmdlet, which applies the security descriptor in the AclObject parameter to all of the files inthe pipeline.

In practice, it is best to use the WhatIf parameter with all Set-Acl commands that can affectmore than one item. In this case, the second command in the pipeline would beSet-Acl -AclObject $NewAcl -WhatIf. This command lists the files that would be affected by thecommand. After reviewing the result, you can run the command again without the WhatIf parameter.

Example 4: Disable inheritance and preserve inherited access rules

$NewAcl = Get-Acl -Path "C:\Pets\Dog.txt"$isProtected = $true$preserveInheritance = $true$NewAcl.SetAccessRuleProtection($isProtected, $preserveInheritance)Set-Acl -Path "C:\Pets\Dog.txt" -AclObject $NewAcl

These commands disable access inheritance from parent folders, while still preserving the existinginherited access rules.

The first command uses the Get-Acl cmdlet to get the security descriptor of the Dog.txt file.

Next, variables are created to convert the inherited access rules to explicit access rules. Toprotect the access rules associated with this from inheritance, set the $isProtected variable to$true. To allow inheritance, set $isProtected to $false. For more information, seeset access rule protection.

Set the $preserveInheritance variable to $true to preserve inherited access rules or $false toremove inherited access rules. Then the access rule protection is updated using theSetAccessRuleProtection() method.

The last command uses Set-Acl to apply the security descriptor of to Dog.txt. When the commandcompletes, the ACLs of the Dog.txt that were inherited from the Pets folder will be applied directlyto Dog.txt, and new access policies added to Pets will not change the access to Dog.txt.

Example 5: Grant Administrators Full Control of the file

$NewAcl = Get-Acl -Path "C:\Pets\Dog.txt"# Set properties$identity = "BUILTIN\Administrators"$fileSystemRights = "FullControl"$type = "Allow"# Create new rule$fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $type$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList# Apply new rule$NewAcl.SetAccessRule($fileSystemAccessRule)Set-Acl -Path "C:\Pets\Dog.txt" -AclObject $NewAcl

This command will grant the BUILTIN\Administrators group Full control of the Dog.txt file.

The first command uses the Get-Acl cmdlet to get the security descriptor of the Dog.txt file.

Next variables are created to grant the BUILTIN\Administrators group full control of the Dog.txtfile. The $identity variable set to the name of auser account. The$fileSystemRights variable set to FullControl, and can be any one of theFileSystemRights values that specifiesthe type of operation associated with the access rule. The $type variable set to "Allow" tospecifies whether to allow or deny the operation. The $fileSystemAccessRuleArgumentList variableis an argument list is to be passed when making the new FileSystemAccessRule object. Then a newFileSystemAccessRule object is created, and the FileSystemAccessRule object is passed to theSetAccessRule() method, adds the new access rule.

The last command uses Set-Acl to apply the security descriptor of to Dog.txt. When the commandcompletes, the BUILTIN\Administrators group will have full control of the Dog.txt.

Parameters

-AclObject

Specifies an ACL with the desired property values. Set-Acl changes the ACL of item specified bythe Path or InputObject parameter to match the values in the specified security object.

You can save the output of a Get-Acl command in a variable and then use the AclObjectparameter to pass the variable, or type a Get-Acl command.

Type:Object
Position:1
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-ClearCentralAccessPolicy

Removes the central access policy from the specified item.

Beginning in Windows Server 2012, administrators can use Active Directory and Group Policy to setcentral access policies for users and groups. For more information, seeDynamic Access Control: Scenario Overview.

This parameter was introduced in Windows PowerShell 3.0.

Type:SwitchParameter
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Exclude

Omits the specified items. The value of this parameter qualifies the Path parameter. Enter apath element or pattern, such as *.txt. Wildcards are permitted.

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:True

-Filter

Specifies a filter in the provider's format or language. The value of this parameter qualifies thePath parameter. The syntax of the filter, including the use of wildcards, depends on theprovider. Filters are more efficient than other parameters, because the provider applies them whenretrieving the objects, rather than having PowerShell filter the objects after they are retrieved.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:True

-Include

Changes only the specified items. The value of this parameter qualifies the Path parameter.Enter a path element or pattern, such as *.txt. Wildcards are permitted.

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:True

-InputObject

Changes the security descriptor of the specified object. Enter a variable that contains the objector a command that gets the object.

You cannot pipe the object to be changed to Set-Acl. Instead, use the InputObject parameterexplicitly in the command.

This parameter was introduced in Windows PowerShell 3.0.

Type:PSObject
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-LiteralPath

Changes the security descriptor of the specified item. Unlike Path, the value of theLiteralPath parameter is used exactly as it is typed. No characters are interpreted aswildcards. If the path includes escape characters, enclose it in single quotation marks (').Single quotation marks tell PowerShell not to interpret any characters as escape sequences.

This parameter was introduced in Windows PowerShell 3.0.

Type:String[]
Aliases:PSPath
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Passthru

Returns an object that represents the security descriptor that was changed. By default, this cmdletdoes not generate any output.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Path

Changes the security descriptor of the specified item. Enter the path to an item, such as a path toa file or registry key. Wildcards are permitted.

If you pass a security object to Set-Acl (either by using the AclObject orSecurityDescriptor parameters or by passing a security object from Get-Acl to Set-Acl), andyou omit the Path parameter (name and value), Set-Acl uses the path that is included in thesecurity object.

Type:String[]
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:True

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

ObjectSecurity

You can pipe an ACL object to this cmdlet.

CommonSecurityDescriptor

You can pipe a security descriptor to this cmdlet.

Outputs

None

By default, this cmdlet returns no output.

FileSecurity

When you use the PassThru parameter, this cmdlet returns a security object. The type of thesecurity object depends on the type of the item.

Notes

This cmdlet is only available on Windows platforms.

The Set-Acl cmdlet is supported by the PowerShell file system and registry providers. As such, youcan use it to change the security descriptors of files, directories, and registry keys.

  • Get-Acl
  • FileSystemAccessRule
  • ObjectSecurity.SetAccessRuleProtection
  • FileSystemRights
Set-Acl (Microsoft.PowerShell.Security) - PowerShell (2024)
Top Articles
Part 107 Most Frequently Asked Questions: Drone License 101
Disputing Credit Card Charges | MyCreditUnion.gov
Star Sessions Imx
Chase Bank Operating Hours
Is Csl Plasma Open On 4Th Of July
Yi Asian Chinese Union
Flights to Miami (MIA)
Vanadium Conan Exiles
Okatee River Farms
How do you mix essential oils with carrier oils?
biBERK Business Insurance Provides Essential Insights on Liquor Store Risk Management and Insurance Considerations
Progressbook Brunswick
Everything You Need to Know About Holly by Stephen King
Cooktopcove Com
Breakroom Bw
Jack Daniels Pop Tarts
How to Store Boiled Sweets
charleston cars & trucks - by owner - craigslist
D10 Wrestling Facebook
Who called you from +19192464227 (9192464227): 5 reviews
91 East Freeway Accident Today 2022
Amazing deals for DKoldies on Goodshop!
Evil Dead Rise - Everything You Need To Know
Pickswise Review 2024: Is Pickswise a Trusted Tipster?
zom 100 mangadex - WebNovel
Okc Body Rub
Parkeren Emmen | Reserveren vanaf €9,25 per dag | Q-Park
Wsbtv Fish And Game Report
Marlene2995 Pagina Azul
Yu-Gi-Oh Card Database
Sinfuldeed Leaked
Missing 2023 Showtimes Near Grand Theatres - Bismarck
2430 Research Parkway
Persona 4 Golden Taotie Fusion Calculator
Wega Kit Filtros Fiat Cronos Argo 1.8 E-torq + Aceite 5w30 5l
The Best Carry-On Suitcases 2024, Tested and Reviewed by Travel Editors | SmarterTravel
Pillowtalk Podcast Interview Turns Into 3Some
Best Restaurants In Blacksburg
Claim loopt uit op pr-drama voor Hohenzollern
Linda Sublette Actress
Busted Newspaper Campbell County KY Arrests
Armageddon Time Showtimes Near Cmx Daytona 12
Seven Rotten Tomatoes
Mbfs Com Login
Todd Gutner Salary
Toomics - Die unendliche Welt der Comics online
Arcanis Secret Santa
Ucla Basketball Bruinzone
Slug Menace Rs3
Hsi Delphi Forum
Secondary Math 2 Module 3 Answers
Used Curio Cabinets For Sale Near Me
Latest Posts
Article information

Author: Gov. Deandrea McKenzie

Last Updated:

Views: 6507

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Gov. Deandrea McKenzie

Birthday: 2001-01-17

Address: Suite 769 2454 Marsha Coves, Debbieton, MS 95002

Phone: +813077629322

Job: Real-Estate Executive

Hobby: Archery, Metal detecting, Kitesurfing, Genealogy, Kitesurfing, Calligraphy, Roller skating

Introduction: My name is Gov. Deandrea McKenzie, I am a spotless, clean, glamorous, sparkling, adventurous, nice, brainy person who loves writing and wants to share my knowledge and understanding with you.