转载请注明出自天外归云的博客园: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站点均会有提示:

SharePoint自动化系列——Create a local user and add to SharePoint的更多相关文章

  1. SharePoint自动化系列——Site/Web/List级别的导航菜单

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 需求:在不同的测试用例中,对脚本中不确定的因素需要和用户交互来确定,比如选择哪个site,选择哪个 ...

  2. SharePoint自动化系列——创建MMS terms

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell脚本实现MMS group.termSet.terms的自动化创建: Add- ...

  3. SharePoint自动化系列——Error features自动deactivate

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ SharePoint Content Deployment prerequisite——Error ...

  4. SharePoint自动化系列——通过PowerShell创建SharePoint Lists

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...

  5. SharePoint自动化系列——通过PowerShell创建SharePoint List Items

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...

  6. SharePoint自动化系列——通过PowerShell创建SharePoint Web

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...

  7. SharePoint自动化系列——通过PowerShell创建SharePoint Site Collection

    通过PowerShell创建SharePoint Site Collection,代码如下: Add-PSSnapin microsoft.sharepoint.powershell function ...

  8. SharePoint自动化系列——Solution auto-redeploy using Selenium(C#)

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 本来的想法是做一个可以自动卸载并且部署新solution到SharePoint farm的tool ...

  9. SharePoint自动化系列——通过Coded UI录制脚本自动化创建SharePoint Designer Reusable Workflow

    Coded UI非常好,我开始还在想,怎么样能让一个通过SharePoint Designer创建的Workflow publish三百五十次?想不到一个好的方法,也不知道SharePoint Des ...

随机推荐

  1. 源码搭建LNMP

      源码安装LNMP 作者:尹正杰   版权声明:原创作品,谢绝转载!否则将追究法律责任.       欢迎加入:高级运维工程师之路 598432640 前言:非常简单的一个平台LNMP,在生产实际环 ...

  2. struts2 标签字体大小

    <style type="text/css"> label{ font-size: 20px; } </style> <s:textfield nam ...

  3. codeforces 520 Two Buttons

    http://codeforces.com/problemset/problem/520/B B. Two Buttons time limit per test 2 seconds memory l ...

  4. Appium-android环境的快速搭建

    1.Android的要求: Android的sdk api>=16 appium支持android在linux,osx(mac),window平台 2.Appium的安装与启动: 安装: (1) ...

  5. Android so lib库远程http下载和动态注册

    一.背景 在开发Android应用程序的实现,有时候需要引入第三方so lib库,但第三方so库比较大,例如开源第三方播放组件ffmpeg库, 如果直接打包的apk包里面, 整个应用程序会大很多.经过 ...

  6. HDU 3691 Nubulsa Expo(全局最小割Stoer-Wagner算法)

    Problem Description You may not hear about Nubulsa, an island country on the Pacific Ocean. Nubulsa ...

  7. mesos资源动态分配测试

    测试集群配置 60CPU,320G RAM 测试内容:先运行一个需要60CPU的Application1,再运行一个需要50CPU的Application2. 结果分析 如果要等Application ...

  8. VS中快速生成json数据格式对应的实体

    JSON是一种取代XML的数据结构,和xml相比,它更小巧但描述能力却不差,由于它的小巧所以网络传输数据将减少更多流量从而加快速度. JSON就是一串字符串 只不过元素会使用特定的符号标注. {} 双 ...

  9. google pinyin elmentary os

    sudo apt-get install software-properties-common for ppa. I have been using Sun Pinyin for quite a lo ...

  10. nginx 优化

    隐藏nginx版本号:在http标签内写server_tokens off; 隐藏apache版本号:ServerTokens Prod ServerSignature Off 更改nginx默认的用 ...