zoukankan      html  css  js  c++  java
  • 用powershell批量新增user profile

     SharePoint 2013 新系统,要在User Profile Service里把人全加一下,其实同步ad更方便,但ad里的人太多,没必要全要,只要大中华区就行了,问hr要了一份人员名单,写了个脚本

    先来个xml,把要加的人ad账号列一下

    <Users>
      <UserName Name="user_a" />
      <UserName Name="user_b" />
      <UserName Name="user_c" />
      <UserName Name="user_d" />
      <UserName Name="user_e" />
      <UserName Name="user_f" />

    </Users>

    再来一段简单的脚本

    #********************************************************************
    # Create New User
    #
    #********************************************************************

    $snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
    if ($snapin -eq $null)
    {
      Write-Host "Loading SharePoint Powershell Snapin..."
      Add-PSSnapin "Microsoft.SharePoint.Powershell"
      Write-Host "SharePoint Powershell Snapin Loaded"
    }
    # Get XML Configuration file
    [xml]$xmlData=Get-Content "C:\test.xml"

    Write-host ""
    Write-host -f Yellow "Starting create new user"

    # create a connection to the User Profile Manager
    $MySite = Get-SPSite <siteUrl>
    $context = Get-SPServiceContext $MySite

    # Get UserProfileManager Object
    $profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

    $xmlData.Users.UserName | ForEach-Object {

      if($profileManager.UserExists($_.Name) -eq $false){
        $profileManager.CreateUserProfile($_.Name)
        Write-host -f Green $_.Name "created"
      }

      else{
        Write-host -f Red $_.Name "already exist"
      }

    }

  • 相关阅读:
    保险实战
    单片机的应用(位操作)
    显示转换(类型转换)
    游泳池的容量
    消失的重量(隐式变换)
    物品交换(变量)
    物品的存放(变量)
    输出变量的界值(int、float、long.....)
    在屏幕上输出内容
    C#笔记
  • 原文地址:https://www.cnblogs.com/graccc/p/3779587.html
Copyright © 2011-2022 走看看