簡體   English   中英

使用Powershell授予對Sharepoint庫中文件夾的權限?

[英]Grant permissions to folder in Sharepoint library using Powershell?

我有一個Sharepoint庫,我有一個Powershell腳本將文件放入其中進行處理。 Powershell腳本可以訪問Active Directory,並返回組成員身份信息。 然后,腳本使用組所有者的名稱在我的媒體庫中為組所有者創建一個文件夾(如果不存在),並將特定組中包含的所有用戶的.CSV拖放到該文件夾​​中。

這里需要的是只授予組所有者的“讀取”權限,這將是我們正在使用的文件夾的名稱。理想情況下,該文件夾將被隱藏,但是我知道使用Sharepoint時存在一些限制。

例如:

John Doe,用戶:jdoe將能夠訪問Z:/jdoe/IT.csv,但不能訪問Z:/someuser/HR.csv

我目前將Sharepoint庫映射到Z:/,以使我的生活更輕松。

我執行了get-command Module Microsoft.SharePoint.PowerShell | ft name 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列表中。

希望能幫助您了解正在發生的事情。 我是否應該假設我應該在Powershell方面而不是在Sharepoint方面進行處理? 如果是這樣,我是否可以通過Grant -SPObjectSecurity朝正確的方向Grant -SPObjectSecurity

謝謝!

更新:

在我在下面的評論中提供的鏈接之后,這是我想到的:

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!"

        }

   }

這是與我的代碼相關的錯誤:

在此處輸入圖片說明

完整的代碼可以在這里找到: http : //pastebin.com/iBpj6V1U

更新#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   

在此處輸入圖片說明

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

我最終意識到,如果我使用Powershell將信息獲取到.CSV,然后最終獲取到Sharepoint,那么實際上浪費時間與文件並通過Powershell直接利用Sharepoint是沒有意義的。

這是我用來完成此操作的代碼: http : //pastebin.com/xRyvXLCB

特別感謝@TheMadTechnician

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM