Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



PowerShell Set-Acl

PowerShell Script Files - Set-Acl

With Set-Acl (Access Control List) you can actually change permissions on files or folders, thus adjust who can see sensitive information.  If you are new to this cmdlet I recommend that you start with the safer, easier Get-Acl before you risk creating a rogue script which locks you out of important areas of the file system.

 ♣

Example: Set-Acl Copy Permissions

The Set-Acl cmdlet changes the security descriptor of a file, to match the values in a security descriptor that you supply.  You can also employ Set-Acl for amending folder or registry permissions.  The best technique that I have found is to use Get-Acl to do the fetching and Set-Acl to do the applying new permissions.

For safety reasons it's better to create a test folder and copy a few unimportant files, rather than risk a novice script running amok on important data files.

Preliminary Steps

  • Have a refresher on Get-Acl
  • Create a new folder, for example C:\Romeo
  • Copy a few unimportant files into your example folder, or else create a few new files with Notepad.

Assumption you have two files.  C:\Romeo\OldUser.txt and C:\Romeo\NewPerson.txt

# PowerShell Example Set-Acl Copy Permissions
Clear-Host
$Source = "C:\Romeo\OldUser.txt"
$Destination = "C:\Romeo\NewPerson.txt"
Get-Acl $Source | Set-Acl -path $Destination

Learning Points

Note 1:  The reason that I used the variable $Source and $Destination is to remind you to change the values of these paths before running this script on your machine.

Note 2:  If you are in anyway uncertain what will happen, remember the -confirm and -whatIf parameters, they are made for situation like this - learning something new which could cripple your machine.

# PowerShell Set-Acl Copy Permissions
Clear-Host
$Source = "C:\Romeo\OldUser.txt"
$Destination = "C:\Romeo\NewPerson.txt"
Get-Acl $Source | Set-Acl -path $Destination -confirm

Challenge:  Use the Windows Explorer to see the actual files, and also use the Advanced button on the property sheet to change permissions on the source file, then run the above example script again.

This is just to check that the script really is copying the permissions from one file to the other.

PowerShell Set-Acl cmdlet

Guy Recommends: Permissions Analyzer - Free Active Directory ToolFree Permissions Monitor

I like the Permissions Monitor because it enables me to see quickly WHO has permissions to do WHAT.  When you launch this tool it analyzes a users effective NTFS permissions for a specific file or folder, takes into account network share access, then displays the results in a nifty desktop dashboard!

Think of all the frustration that this free utility saves when you are troubleshooting authorization problems for users access to a resource.

Download Permissions Analyser - Free Active Directory Tool

Research Set-Acl Parameters

# PowerShell Set-Acl Parameters
Clear-Host
Get-Help Set-Acl -full

Checking the help file will reveal useful parameters, for instance the -force switch maybe useful for your task.  In addition to the file system you can also use Set-Acl to change permissions on registry keys.

Background Research

In addition to pure PowerShell Set-Acl research I strongly recommend that open Windows Explorer and look at not only the location of the files, but also at the permissions.

If you right-click any file or folder, select properties and check the permissions. For further detail click Edit, see screenshot to the right.

Another useful technique is to use CACLS

Guy Recommends:  Solarwinds' Free Bulk Import ToolFree Download of Solarwinds  Bulk Import Tool

Import users from a spreadsheet.  Just provide a list of the users with their fields in the top row, and save as .csv file.  Then launch this FREE utility and match your fields with AD's attributes, click to import the users.  Optionally, you can provide the name of the OU where the new accounts will be born.

There are also two bonus tools in this free download, and all 3 have been approved by Microsoft:

  1. Bulk-import new users into Active Directory.
  2. Seek and zap unwanted user accounts.
  3. Find inactive computers.

Download your FREE bulk import tool.

Researching Similar PowerShell Content Cmdlets

# PowerShell Content Cmdlet Research
Clear-Host
Get-Command -noun Acl

This reveals the sister command Get-Acl.  Incidentally, many of PowerShell's Get verbs also have a 'Set' companion cmdlet. 

Summary of PowerShell's Set-Acl

Set-Acl is rather different from the mainstream PowerShell cmdlets, it's designed to modify the access control list of a file, to match the values you supply through the sister command Get-Acl.  You can also employ Set-Acl for amending folder or registry permissions.

If you like this page then please share it with your friends

 


See more PowerShell share examples including WMI

PowerShell WMI   • Win32_Share   • WMI Shares   • Query

Get-Acl  • PowerShell Error Codes   • Win32_ComputerSystem

Please email me if you have a example scripts. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, Solarwinds have created the Free WMI Monitor so that you can actually see and understand these gems of performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

 

Home Copyright © 1999-2012 Computer Performance LTD All rights reserved

Please report a broken link, or an error.