开发者

PowerShell - New-SPWeb with UniquePermissions

开发者 https://www.devze.com 2023-02-09 14:35 出处:网络
I want to create a new SPWeb with PowerShell. My code creates the site and add the group to the site but not the user \"TestUser1\".

I want to create a new SPWeb with PowerShell. My code creates the site and add the group to the site but not the user "TestUser1". The test\testuser1 belongs not to the TestGroup1 and get intepend permissions.

 $web = New-spweb http://http:/mysharepointurl/site/web -Template "STS#0" -UniquePermissions 

$user = $web.EnsureUser('test\testuser4')

$web.Users.AddUser($user, "Full") #Not working, Add a 开发者_如何学编程existing User

$newGroup = $web.SiteGroups["TestGroup6"] #Working, Add a existing Group
$web.Roles["Full"].AddGroup($newGroup)


Have you tried

$web.Users.Add -or- $web.AllUsers.Add

public void Add(
    string loginName,
    string email,
    string name,
    string notes
)

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spusercollection.add.aspx


You are using New-SPWeb, so that means you need to be adding users to the SPWeb.

$web.SiteUsers is the site collection group

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.siteusers.aspx

You should use

$web.Users

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.users.aspx


My working solution:

$web = Get-SPWeb "http://http:/mysharepointurl/site/web" 
$user = $web.AllUsers["test\testuser1"]
$roledef = $web.RoleDefinitions["Vollzugriff"]
$roleass = New-Object Microsoft.SharePoint.SPRoleAssignment($user)
$roleass.RoleDefinitionBindings.Add($roledef)
$web.RoleAssignments.Add($roleass)
$web.Update()

Thanks for the support!

0

精彩评论

暂无评论...
验证码 换一张
取 消