Change folder permissions

Welcome Forums General PowerShell Q&A Change folder permissions

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years, 7 months ago.

  • Author
  • #5053

    Topics: 1562
    Replies: 0
    Points: 0
    Rank: Member

    by 97browng at 2012-08-28 08:41:08

    Hi All,

    I am a new user of powershell and was wondering if anyone could help. Basically I want to change the permissions of one folder so that users have full access. I have worked out that I can copy the folder permissions of another file with the correct settings and use something like the below;

    $acl = get-acl "\\PC1\D$\BlankFolder"
    set-acl "PC2\C$\Teating"

    Now my problem is that I want to run it on several machines. I have a list of the machines (lets say PC3 – PC100) stored in a .txt file.

    My first questions is how can I get it so that powershell changes the folder permissions on each PC. The text file has each computer on a seperate line (I use it for batch scripts) and lets say it is in the same place as I run powershell from and called PC_List (\\PC1\D$\Scripts\PC_List.txt). I assume I use the get-content command here?

    My second questions is how can I make a log of the successful changes and unsuccessful ones? When copying files via my batch scripts if a file copies without issues it would write the PC name in a .txt file callesd success and if there were any errors it would write the PC name in a .txt called fail. Something like this would be very useful again.

    Any help would be much appreciated.


    by DonJ at 2012-08-28 08:49:21

    So, something like this:

    $computers = Get-Content "computernames.txt"
    foreach ($computer in $computers) {
    # $computer has a computer name - use it in your UNC
    # e.g., $unc = "\\$computer\d$\whatever\folder\name"

    In terms of catching errors.

    Try {
    Set-ACL "whatever" -ErrorAction Stop
    } catch {
    # log the error here - use Out-File to write to a log file, for example.

The topic ‘Change folder permissions’ is closed to new replies.