-
Notifications
You must be signed in to change notification settings - Fork 1
/
Start-UserProfileSync.ps1
58 lines (48 loc) · 1.72 KB
/
Start-UserProfileSync.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<#
.SYNOPSIS
Starts User Profile Synchronization Service Instance
.DESCRIPTION
25/06/2015
12/12/2015: updated process to start and check status
14/02/2016: updated for Atos scripts
.NOTES
File Name : Start-UserProfileSync.ps1
Author : Spencer Harbar ([email protected])
Requires : PowerShell Version 2.0
.LINK
.PARAMETER File
The configuration file
#>
#region PARAMS
param (
[String]$Server,
[String]$UpaName,
[PSCredential]$FarmAccount
)
#endregion PARAMS
#region MAIN
try {
If ((Get-PSSnapin -Name "Microsoft.SharePoint.PowerShell" -EA 0) -eq $null) { Add-PSSnapin -Name "Microsoft.SharePoint.PowerShell" }
Write-Host "$(Get-Date -Format T) : Starting the User Profile Synchronization service..."
Write-Host "$(Get-Date -Format T) : This normally takes about 5 minutes..." -ForegroundColor Yellow
$UpsInstanceName = "User Profile Synchronization Service"
$Upa = Get-SPServiceApplication | where-object {$_.Name -eq $UpaName}
$Ups = Get-SPServiceInstance -Server $Server | where-object {$_.TypeName -eq $UpsInstanceName}
$Ups.UserProfileApplicationGuid = $Upa.Id
$Ups.Update()
$Upa.SetSynchronizationMachine($Server, $Ups.Id , $FarmAccount.UserName, $FarmAccount.GetNetworkCredential().Password)
$Upa.Update()
Start-SPServiceInstance -Identity $Ups | Out-Null
while((Get-SPServiceInstance -Server $Server | where-object {$_.TypeName -eq $UpsInstanceName}).Status -ne "Online"){
Start-Sleep 60
}
Write-Host "$(Get-Date -Format T) : UPS Started!" -ForegroundColor Green
}
catch {
Write-Host "OOOPS! We failed during starting UPS on $server." -ForegroundColor Red
$_
Exit
}
#endregion MAIN
#EOF