Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Assigning unique folder permissions in SharePoint libraries via PowerShell

$
0
0

Hi guys,

Another SharePoint question for you.

What I'm basically trying to do is assign one user permissions to one folder in a document library.

I have 464 domain users, a subsite called "Personal Folders" and 464 folders named after the users in the "Shared Documents" library. I need to give username "JBloggs" Contribute access to the folder called "Joe Bloggs" and then give "JDoe" Contribute access to the folder called "John Doe" etc etc etc.

I don't fancy doing this on all 464 folders via the GUI so here's what I've got so far:

I have a CSV file which contains the columns FullName and UserName with a list of the names and respective usernames for every user. My script is currently capable of creating all the folders and naming them after the column "FullName" but is not able to then assign the contribute permission to the "UserName" column.

With me so far?! OK here's the actual script (it's not launched directly, there is another script which calls it - I can't take credit for this script, it's from http://thesharepointproject.com/2012/08/04/create-multiple-folders-in-a-library-based-on-a-csv-file)

Param (
           [parameter(Mandatory=$true)][string]$SiteUrl,
           [parameter(Mandatory=$true)][string]$LibraryName,
           [parameter(Mandatory=$true)][string]$CSVPath
           )

    # Import CSV
    [array]$FolderList = Import-Csv $CSVPath

    # Script Variables
    $spWeb = Get-SPWeb $SiteUrl
    $spList = $spWeb.Lists[$LibraryName]

    Foreach ($folderGroup in $FolderList) {

  # Create Parent Folder
        $parentFolder = $spList.Folders.Add("",[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$folderGroup.FullName)
        #$parentFolder.BreakRoleInheritance($true); #break inheritance
  $parentFolder.Update()
        Write-Host "The Parent folder" $folderGroup.FullName "was successfully created" -foregroundcolor Green
  $parentFolder.BreakRoleInheritance($true); #break inheritance

Anyone got any ideas how to get this script to read the second column of the csv and add the contribute permission to the folder it has just created?!

As always, massive thanks in advance!

Adam


Viewing all articles
Browse latest Browse all 15370

Latest Images

Trending Articles



Latest Images