故事git
最近,生产环境上线,好多好多用户组须要配置,一大批人要分别加到各类组,BA的手都点麻了,花了一天时间干活,又花了大半天时间作检查。程序员
而后,你们就一块儿讨论这个事儿,这样既费时费力,又没法保证正确的事情,咱们该怎么解决呢?github
解决方法web
做为机智的程序员,必定能够解决这个问题的,由于咱们都是很(ai)聪(tou)明(lan)的代码者!!!api
好吧,运维利器PowerShell 命令又该出场了!掌声在哪里?运维
做为需求分析员,只须要把上线数据准备好,放到CSV文件里,以下:oop
Tips:我这里把域名放在用户名了,其实,更(tu)严(sheng)谨(shi)的状况,能够把域名放到代码中:测试
PowerShell 代码spa
Tips:代码逻辑很简单,读取CSV文件,找到站点的用户组,一个一个添加就行了;code
Add-PSSnapin Microsoft.SharePoint.PowerShell #Read CSV file $CSVData = Import-CSV -path "C:\UserList.csv" #Set $WebUrl = "http://sitecollection/sites/PM" $GroupName = "PM Members" #Get the Web $web=Get-SPWeb $WebUrl #Get the SharePoint Group $Group= $web.Groups[$GroupName] #Loop every Row in the CSV foreach ($Row in $CSVData) { #Get UserName $userName = $row.UserName #Add User to the site collection $user = $web.EnsureUser($UserName) #Add User to the Group $group.AddUser($user) Write-Host "Added User: " $row.UserName -ForegroundColor Green }
添加完毕之后的截图(怎么这么少?测试数据啊,Small GeGe&Small JieJie们)
结束语
遇到困难,不要伤心,不要惧怕,记得想起咱们的运(tou)维(lan)利器 PowerShell 命令。
更多经常使用PowerShell脚本,请关注https://github.com/linyus