Adding groups to folders

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Jarek C. Jarek C. 1 year, 9 months ago.

  • Author
    Posts
  • #22826
    Profile photo of Jarek C.
    Jarek C.
    Participant

    I need to add groups to folders where the group name gives a hint as to what folder it should be added so say I have a

    system
    application
    logs
    ... etc.

    folders and then

    System Group
    Application Group
    Logs Group
    ....etc.

    I know that I can do the testing with
    FunctionFolderTest($folders){
    foreach($folder in $folders){
    if(!(Test-Path $folder)){
    New-Item -Path $folder -ItemType Directory -force
    }
    }
    }

    And for the groups

    function LocalGroupExist($groupName)
    {
    return [ADSI]::Exists("WinNT://$env:COMPUTERNAME/$groupName,group")
    }
    Which can be run through for each.

    Assuming the groups exist and the folders exist having a list of both in a txt file how do I go about adding the right group to the right folder?

  • #22827
    Profile photo of Don Jones
    Don Jones
    Keymaster

    I assume you mean "adding a group to the folder's ACL." Check out the Get-ACL and Set-ACL commands; natively, they're the only real way to manipulate ACLs.

  • #22831
    Profile photo of Jarek C.
    Jarek C.
    Participant

    Pretty much so. Thanks for the tip.

You must be logged in to reply to this topic.