转载请注明出自天外归云的博客园: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. Leetcode: Range Sum Query 2D - Mutable && Summary: Binary Indexed Tree

    Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...

  2. [原创]java WEB学习笔记83:Hibernate学习之路---双向 1-n介绍,关键点解释,代码实现,set属性介绍(inverse,cascade ,order-by )

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  3. [转]jQueryEasyUI Messager基本使用

    一.jQueryEasyUI下载地址 http://www.jeasyui.com/ 二.jQueryEasyUI Messager基本使用 1.$.messager.alert(title, msg ...

  4. PHP-字符串过长不用担心

    字符串过长可以用定界符: >>>GOD ................巨长务必的字符串 GOD;

  5. 如何彻底卸载MySQL

    如何彻底卸载MySQL 下面给出完整的卸载MySQL 5.1的卸载方法: 1.控制面板里的增加删除程序内进行删除 2.删除MySQL文件夹下的my.ini文件,如果备份好,可以直接将文件夹全部删除 3 ...

  6. (转)Aspone.Cells设置Cell数据格式 Setting Display Formats of Numbers and Dates

    Setting Display Formats Using Microsoft Excel: Right-click on any desired cell and select Format Cel ...

  7. 解决maven编译spark1.5报错问题

    spark1.5发布了,赶紧去下了源码尝鲜 git clone git://github.com/apache/spark.git -b branch-1.5 输入命令进行编译 ./make-dist ...

  8. dataset 使用

    下面有例子说明: 首先我们需要打开一个联结: string MyConnString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:/ ...

  9. RMAN备份演练初级篇

    前面我们已经知道了如何进入rman,以及rman的一些基本命令,相信大家定会觉着rman操作的简单,事实也确实如此,但万不要因此小视rman的强大,简单往往意味着灵活,灵活对于那些有心人则意味着主动权 ...

  10. 关于wxwidgets图形界面的关闭窗口的按钮无效的解决办法

    这是使用wxsmith设计界面时的情况,如果用纯代码写的界面,关闭按钮就很奇怪地有效 道听途说,窗口的关闭是由一个方法控制着.大概是这样的: void PlainFrame::OnClose(wxCl ...