SharePoint自动化系列——Create a local user and add to SharePoint

简介: 转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 实现过程:在本地创建一个local user并将该user添加到Administrators组中,然后在SharePoint指定site中添加该user,并赋予Full Control的权限。

转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/

实现过程:在本地创建一个local user并将该user添加到Administrators组中,然后在SharePoint指定site中添加该user,并赋予Full Control的权限。

脚本如下: 

function AddUserToSPSite
{
    param($siteUrl,$userName,$pwd,$fullName,$dspt)
    #Create a local user and add to a local group.
    try{
        $computer = [ADSI]"WinNT://$Env:COMPUTERNAME,Computer"
        $user = $Computer.Create("User", $userName)
        $user.SetPassword($pwd)
        $user.SetInfo()
        $user.FullName = $fullName
        $user.Description = $dspt
        # ADS_UF_PASSWD_CANT_CHANGE + ADS_UF_DONT_EXPIRE_PASSWD
        $user.UserFlags = 64 + 65536 
        $user.SetInfo()
        $group = [ADSI]"WinNT://./Administrators,group"
        $group.Add("WinNT://$userName,user")
    }catch
    {
        Write-Warning "User exists in local, no need to create new."
    }
    #Add the new created local user to a SharePoint site.
    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
    {
        Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    }
    $site = Get-SPSite $siteUrl
    $web = $site.rootWeb
    $SPUserName = $env:COMPUTERNAME+"\"+$userName
    $user = New-SPUser -UserAlias $SPUserName -DisplayName $userName -Web $web
    Set-SPUser -Identity $user -Web $web -AddPermissionLevel "Full Control"
}
AddUserToSPSite -siteUrl "http://xxx" -userName "xxx" -pwd "xxx" -fullName "xxx" -dspt "xxx"

如果本地已经存在欲添加的user以及成功添加user到SharePoint站点均会有提示:

相关文章
|
安全 开发工具 IDE
SharePoint自动化系列——Error features自动deactivate
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ SharePoint Content Deployment prerequisite——Error features deactivate automation 对于Content Depl...
1162 0
SharePoint自动化系列——通过PowerShell创建SharePoint List Items
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PSSnapin microsoft.
892 0
SharePoint自动化系列——通过PowerShell创建SharePoint Lists
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PSSnapin microsoft.
899 0
SharePoint自动化系列——通过PowerShell创建SharePoint Web
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PSSnapin Microsoft.
819 0
SharePoint自动化系列——通过PowerShell创建SharePoint Site Collection
通过PowerShell创建SharePoint Site Collection,代码如下: Add-PSSnapin microsoft.sharepoint.powershell function CreateTeamSite() { $webApps = Get-SPWebApplication $webAppsUrl = $webApps.
870 0
|
Go C# Windows
SharePoint自动化系列——Solution auto-redeploy using Selenium(C#)
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 本来的想法是做一个可以自动卸载并且部署新solution到SharePoint farm的tool。
1010 0
|
索引 存储
SharePoint自动化系列——Set MMS field value using PowerShell.
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 本章将总结一下设置SharePoint list中item的Managed Metadata field value的方法。
780 0
SharePoint自动化系列——Upload files to SharePoint library using PowerShell.
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 日常的SharePoint站点测试中,我们经常要做各种各样的数据,今天又写了几个脚本,发现自己写的脚本越来越多,所以我决定整理一下,并把一些常用的可复用的方法陆续发布上来。
1131 0
SharePoint自动化系列——通过PowerShell在SharePoint中批量做数据
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell是基于.NET的一门脚本语言,对于SharePoint一些日常操作支持的很好。
1112 0
|
Web App开发
SharePoint自动化系列——通过Coded UI录制脚本自动化创建SharePoint Designer Reusable Workflow
Coded UI非常好,我开始还在想,怎么样能让一个通过SharePoint Designer创建的Workflow publish三百五十次?想不到一个好的方法,也不知道SharePoint Designer里那个publish按钮调用的是什么方法,想来想去还是用Coded UI尝试了一下,发现也挺好,在资源允许的情况下,就这样完成了SPD Workflow的自动化创建: 1.
931 0

热门文章

最新文章