powershell powershell脚本将用户添加到指定SharePoint网站中的指定组。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell powershell脚本将用户添加到指定SharePoint网站中的指定组。相关的知识,希望对你有一定的参考价值。

Add-PSSnapin Microsoft.SharePoint.PowerShell
Function AddUsers($userArray, $webUrl, $group)
{
    foreach ($user in $userArray)
    {
        $username = $user[0];
        ##Set-SPUser -Identity $username -Web $webUrl -Group $group
		#Get the site name to the variable
		$web = Get-SPWeb $webUrl
		#Get the group name to the variable
		$groupName = $web.SiteGroups[$group]
		#Assign user to variable
		$user = $web.Site.RootWeb.EnsureUser($username)
		#Add user to group 
		$groupName.AddUser($user)
		Write-Host -ForegroundColor green "User Added Successfully"
    }
}

$userArray = @(
    @("scu\JCharlton"),
    @("scu\BHerring"),
    @("scu\MGranger"),
	@("scu\CHenson"),
	@("scu\DRutledge"),
	@("scu\JMcDougal"),
	@("scu\DJackson"),
	@("scu\SRichardson"),
	@("scu\Brame")
    )

#Call function without brackets
AddUsers $userArray "http://scushp01/IT/Projects/2016TS" "2016 Technical Support Members"
AddUsers $userArray "http://scushp01/IT/Projects/2016IF" "2016 Infrastructure Members"
AddUsers $userArray "http://scushp01/IT/Projects/2016Dev" "2016 Development Members"

以上是关于powershell powershell脚本将用户添加到指定SharePoint网站中的指定组。的主要内容,如果未能解决你的问题,请参考以下文章

powershell怎么运行

powershell [PS:脚本模板]只是PowerShell脚本要遵循的模板。 #PowerShell #Template

powershell脚本隐藏退出码

powershell 测量PowerShell命令或PowerShell脚本的速度

PowerShell 添加任务以使用参数运行 PowerShell 脚本

PowerShell命令与脚本(10)——脚本