PowerShell - 具有UniquePermissions的New-SPWeb

时间:2011-02-07 12:34:23

标签: sharepoint powershell sharepoint-2010 powershell-v2.0

我想用PowerShell创建一个新的SPWeb。 我的代码创建了网站并将该组添加到网站,但不是用户“TestUser1”。 test \ testuser1不属于TestGroup1并获得了权限。

 $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)

3 个答案:

答案 0 :(得分:2)

你试过吗

$web.Users.Add - 或 - $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

答案 1 :(得分:1)

您正在使用New-SPWeb,这意味着您需要将用户添加到SPWeb

$web.SiteUsers是网站集

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

你应该使用

$web.Users

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

答案 2 :(得分:1)

我的工作解决方案:

$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()

感谢您的支持!