首页 文章

使用Powershell为Sharepoint库中的文件夹授予权限?

提问于
浏览
0

我有一个Sharepoint库,我有一个Powershell脚本将文件放入处理中 . Powershell脚本可以访问Active Directory,并返回组成员身份信息 . 然后,该脚本使用组所有者的名称为我的库中的组所有者(如果它不存在)创建一个文件夹,并将特定组中包含的所有用户的.CSV删除到该文件夹中 .

这里需要的是仅向组的所有者授予“读取”权限,这将是我们正在使用的文件夹的名称 . 理想情况下,文件夹将被隐藏,但是我知道使用Sharepoint时存在限制 .

例如:

John Doe,用户:jdoe可以访问Z:/jdoe/IT.csv但不能访问Z:/someuser/HR.csv

我将我的Sharepoint库映射到Z:/目前,让我的生活更容易为Powershell .

我执行了 get-command Module Microsoft.SharePoint.PowerShell | ft name 并浏览了Sharepoint命令列表 .

然后我偶然发现了 Grant-SPObjectSecurity Cmdlet ,我认为这是我想在Powershell端使用的,当创建文件夹时,只将Sharepoint权限应用于为其创建文件夹的用户 .

从开始到结束的过程是:Powershell脚本'Get_Group_Members'执行,每行读取包含Active Directory组名称的文本文件 . 对于找到的每个组,脚本标识组的所有者,创建以所有者AD名称命名的文件夹,并将.CSV文件放在列出该组的所有成员的文件夹中 . 然后,我(现在无论如何)手动启动下一个脚本'Import_CSV',它将所有信息提取到一个不相关进程的Sharepoint列表中 .

希望有助于了解's happening. Am I right in assuming I should handle this on the Powershell side, as opposed to the Sharepoint side? If so, am I headin'在 Grant -SPObjectSecurity 正确的方向?

谢谢!

Update:

按照我在下面的评论中提供的链接,这是我想出的:

function GrantUserpermission($strOwnerName)
    {
    [Microsoft.SharePoint.SPUserCollection]$spusers=[Microsoft.SharePoint.SPUserCollection]$web.SiteUsers
    [Microsoft.SharePoint.SPUser]$spuser=$spusers[$strOwnerName]

        "Strowner name: " + $strOwnerName

        # Get the SPWeb object and save it to a variable
        $web = Get-SPWeb -identity $WebURL
        if ($strOwnerName -ne $null)

        {
            $sproleass=new-object Microsoft.SharePoint.SPRoleAssignment([Microsoft.SharePoint.SPPrincipal]$spuser)
            $folder.BreakRoleInheritance("true")
            $sproleass.RoleDefinitionBindings.Add($web.RoleDefinitions["Contribute"])
            $folder.RoleAssignments.Add($sproleass);
            Write-Host "Permission provided for user ", $strOwnerName
        }

        else

        {

        Write-Host "User ""$userName"" was not found in this web!"

        }

   }

在这里,是与我的代码相关的错误:

enter image description here

完整代码可在此处找到:http://pastebin.com/iBpj6V1U

Update #2

#apply permissions to folder
    "Strowner name: " + $strOwnerName
    function GrantUserpermission($strOwnerName)
    {

    $web = Get-SPWeb -identity $WebURL
    [Microsoft.SharePoint.SPUser]$spuser=$web.EnsureUser($strOwnerName)
    "Strowner name in Function: " + $strOwnerName

enter image description here

更新代码#2:http://pastebin.com/DzP1hVce

1 回答

  • 0

    我最终意识到,如果我使用Powershell将信息传递给.CSV,然后最终传递给Sharepoint,那么实际上浪费文件时间并通过Powershell直接点击Sharepoint是没有意义的 .

    这是我用来完成此任务的代码:http://pastebin.com/xRyvXLCB

    特别感谢@TheMadTechnician

相关问题