Quantcast
Channel: Microsoft Online: SharePoint Online forum
Viewing all articles
Browse latest Browse all 10096

give permissions to files file share to sharepoint online

$
0
0

I have this code that adds the permissions to folders from a fileshare to the same file share in office 365. How can I make it so it add the files permissions as well?

FunctionMapPermissions{[CmdletBinding()]
param([Parameter(Mandatory=$true)][string]$SiteURL,[Parameter(Mandatory=$true)][string]$Folder,[Parameter(Mandatory=$true)][string]$DocLibName,[Parameter(Mandatory=$false)][System.Net.NetworkCredential]$credentials)
$AllFolders =Get-ChildItem-Recurse-Path $Folder |?{$_.psIsContainer -eq $True}
$hashpermfolder =@{}
$GroupPermissionsList=IMPORT-CSV $ScriptDir\$permissionmap
$Context =New-ObjectMicrosoft.SharePoint.Client.ClientContext($SiteURL)
$pass =ConvertTo-SecureString $credentials.Password-AsPlainText-Force
$Creds =New-ObjectMicrosoft.SharePoint.Client.SharePointOnlineCredentials($credentials.UserName,$pass)
$Context.Credentials= $Creds#Retrieve list
$List = $Context.Web.Lists.GetByTitle($DocLibName)
$Context.Load($List)
$Context.ExecuteQuery()
$count=1
$web = $context.Web
$context.Load($web)
$context.ExecuteQuery()
 
foreach($CurrentFolder in $AllFolders){
$global:test =$false#Set the FolderRelativePath by removing the path of the folder supplied by the operator from the fullname of the folder
$FolderRelativePath =($CurrentFolder.FullName).Substring($Folder.Length)
$FileSource = $Folder + $FolderRelativePath
$FilesInFolder =Get-ChildItem-Path $FileSource |?{$_.psIsContainer -eq $False}
$groupuser =@((Get-Acl $FileSource).Access|Select-Object-ExpandPropertyIdentityReference)
$inherit =@((Get-Acl $FileSource).Access|Select-Object-ExpandPropertyIsInherited)
$pat ="^[a-zA-Z0-9\s._]+$"
$pos = $FolderRelativePath.LastIndexOf("\")
$FolderCurrent = $FolderRelativePath.Substring($pos+1)
if(!($FolderCurrent -match $pat)){
$arrlength=$hashpermfolder.count +1
$dividend = $arrlength;
$columnName =''
$modulo;
while ($dividend -gt 0)
{
$modulo = ($dividend - 1) % 26;
$columnName = [char](65 + $modulo) + $columnName;
$dividend = [int](($dividend - $modulo) / 26);
}
$columnName = $columnName + '_'
$oldChunk = $FolderCurrent
$hashpermfolder.Add($columnName,$oldChunk)
$newfolder = $FolderCurrent -replace '[#?%&*\\:<>/|"\{\[\(\)\]\}]', "_$columnName"
$FolderRelativePath = $FolderRelativePath -replace $oldChunk, $newfolder
}
if(($inherit -contains $false)){
foreach($group in $GroupPermissionsList){
foreach($groups in $groupuser)
{
$isgroup=$false
if([string]$groups -eq [string]$group.NovellGroup){
$groupAD = $group.SPGroup
$isgroup=$true
write-host "The Novell group $groups has been changed to the AD group $groupAD"
}
$permission = @((Get-Acl $FileSource).Access | Where{$_.IdentityReference -eq [String]$groups }).FileSystemRights
$permission = [String]$permission
if($permission.contains("Write")){
$permission = "Contributor"
$roletype = [Microsoft.SharePoint.Client.RoleType]$permission
$roleDefs = $web.RoleDefinitions
$context.Load($roleDefs)
$context.ExecuteQuery()
$roleDef = $roleDefs | where {$_.RoleTypeKind -eq $roletype}
 
}elseif($permission.contains("Read")){
$permission = "Reader"
$roletype = [Microsoft.SharePoint.Client.RoleType]$permission
$roleDefs = $web.RoleDefinitions
$context.Load($roleDefs)
$context.ExecuteQuery()
$roleDef = $roleDefs | where {$_.RoleTypeKind -eq $roletype}
}
if($permission.contains("FullControl")){
$permission = "Administrator"
$roletype = [Microsoft.SharePoint.Client.RoleType]$permission
$roleDefs = $web.RoleDefinitions
$context.Load($roleDefs)
$context.ExecuteQuery()
$roleDef = $roleDefs | where {$_.RoleTypeKind -eq $roletype}
}
function GetChildFolders($RootFolder)
{
if($count -ne 1){
$folderName=$folderName+'\'+$RootFolder.Name}
$Context.Load($RootFolder)
$Context.Load($RootFolder.Folders)
$Context.ExecuteQuery()
$count++if($folderName -eq $FolderRelativePath){
$item = $RootFolder.ListItemAllFieldsif($global:test -eq $false){
$item.BreakRoleInheritance($false,$false)
$Context.Load($item)
$context.ExecuteQuery()Write-host "Inheritance Broken"
$global:test =$true}if($isgroup -eq $true){
$groups = $web.SiteGroups
$context.Load($groups)
$context.ExecuteQuery()
$group = $groups |where{$_.Title-eq $groupAD}}else{
$domainUser = $groups -replace '\\','/'
$fullUserName =([adsi]"WinNT://$domainUser,user").fullname
$groups =[string]$fullUserNameif($groups -eq ''){
$groups ="Rob Ireland"}$pos = $SiteURL.IndexOf("^([^/]*/){2}[^/]* ")if($pos -gt 0){
                             $userwebs = $SiteURL.Substring(0,$pos)
                             $Contexts =New-ObjectMicrosoft.SharePoint.Client.ClientContext($userwebs)}else{
                           $Contexts =New-ObjectMicrosoft.SharePoint.Client.ClientContext($SiteURL)}
$pass =ConvertTo-SecureString $credentials.Password-AsPlainText-Force
$Creds =New-ObjectMicrosoft.SharePoint.Client.SharePointOnlineCredentials($credentials.UserName,$pass)
$Contexts.Credentials= $Creds
$Users = $Contexts.Web.SiteUsers
$Contexts.Load($Users)
$Contexts.ExecuteQuery()#Create Peopl
$isuser = $falseForeach($User in $Users){if($user.Title-eq $groups){
$isuser = $true}}if($isuser -eq $true){
$group = $Context.Web.EnsureUser($groups)}}if($isuser -eq $true){
$collRdb =new-objectMicrosoft.SharePoint.Client.RoleDefinitionBindingCollection($context)
$collRdb.Add($roleDef)
$collRoleAssign = $item.RoleAssignments
$rollAssign = $collRoleAssign.Add($group, $collRdb)
$context.ExecuteQuery()Write-host "$Permission have been added at $folderName for $groups"}}foreach($folder in $RootFolder.Folders){GetChildFolders $folder}}GetChildFolders $List.RootFolder
$count =1}}}}}

Viewing all articles
Browse latest Browse all 10096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>