Start User Profile Synchronization Service through Powershell cmd


Start User Profile Synchronization Service through Powershell cmd

Function ConvertTo-UnsecureString

([System.Security.SecureString]$string)    {    $unmanagedString =

[System.Runtime.InteropServices.Marshal]::SecureStringToGlobalAllocUni

code($string)     $unsecureString =

[System.Runtime.InteropServices.Marshal]::PtrToStringUni

($unmanagedString)

[System.Runtime.InteropServices.Marshal]::ZeroFreeGlobalAllocUnicode

($unmanagedString)            return $unsecureString      }

$syncMachine = Get-SPServer “sp2010dev” $profApp = Get-SPServiceApplication | where {$_.Name -eq “User Profile

Service Application 1”} $account = Get-Credential “localdev\spfarm” if ($syncMachine.Address -eq $env:ComputerName) {     $syncSvc = Get-SPServiceInstance -Server $env:ComputerName | where

{$_.TypeName -eq “User Profile Synchronization Service”}     $syncSvc.Status =

[Microsoft.SharePoint.Administration.SPObjectStatus]::Provisioning     $syncSvc.IsProvisioned = $false     $syncSvc.UserProfileApplicationGuid = $profApp.Id     $syncSvc.Update()     $profApp.SetSynchronizationMachine($syncMachine.Address,

$syncSvc.Id, $account.UserName, (ConvertTo-UnsecureString

$account.Password)) }

if ($syncSvc.Status -ne “Online”) {     Write-Host “Starting User Profile Synchronization Service…”     Start-SPServiceInstance $syncSvc } do {Start-Sleep 2} while ((Get-SPServiceInstance -Server

$env:ComputerName | where {$_.TypeName -eq “User Profile

Synchronization Service”}).Status -ne “Online”)

Advertisements

About sharepointsriram

9+ Yrs of IT experience
This entry was posted in Sharepoint 2010 User Profiles. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s