This script can help system administrators to start all the Lync Server services for each computer in current topology automatically.
System administrators may encounter that Lync servers are not working properly due to required services startup failure. We can create PowerShell script to help them start these services automatically.
This script contains the following functions:
You can use this script in following ways:
Method 1:
Method 2:
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
Function Start-OSCLyncServicesOnEachServer
{
<#
.SYNOPSIS
Start-OSCLyncServicesOnEachServer can be used to start all the Lync Server services in topology except the Edge server.
.DESCRIPTION
Start-OSCLyncServicesOnEachServer is a function which can be used to start all the Lync Server services in topology except the Edge server.
.EXAMPLE
PS: Start-OSCLyncServicesOnEachServer
.LINK
Windows PowerShell Advanced Function
http://technet.microsoft.com/en-us/library/dd315326.aspx
#>
if((Test-OSCCommonLyncInstalled))
{
if((Test-OSCCommonIsEdgeServer))
{
Write-Host $Messages.NoEdgeRun -ForegroundColor Yellow
return
}
$me = whoami
$currentUser = Get-CsAdUser -Identity $me
$userName = $currentUser.SamAccountName
$roles = Get-CsAdminRoleAssignment -Identity $userName
$adminRole = $roles | Where-Object {$_ -eq "CsAdministrator"}
if($adminRole -ne $null)
{
$servers = @()
#Returns information about the Edge Servers used in your organization.
$edges = @(Get-CsService -EdgeServer)
Get-CsManagementStoreReplicationStatus | ForEach-Object {
$lyncServerName = $_.ReplicaFqdn
foreach($edge in $edges)
{
if(-not($edge.Identity -like "*$lyncServerName"))
{
$servers += $lyncServerName
}
}
}
foreach($server in $servers)
{
Write-Host (-join $Messages.StartingServices,$server,$Messages.StartingServices2) -ForegroundColor Yellow
$conn = Test-Connection -ComputerName $server -Count 1 -ErrorAction:SilentlyContinue
if($conn -eq $null)
{
Write-Host (-join ($Messages.CannotConnect," ",$server)) -ForegroundColor Red
}
else
{
try
{
$services = Get-Service -ComputerName $server -DisplayName "*lync*" -ErrorAction SilentlyContinue
$services | ForEach-Object {
if($_.Status -eq "Stopped")
{
$serviceName = $_.DisplayName
try
{
$_.Start()
$_.WaitForStatus([System.ServiceProcess.ServiceControllerStatus]::Running,[TimeSpan]::FromSeconds(15))
Write-Host (-join ($serviceName," ",$Messages.IsStarted))
}
catch [InvalidOperationException]
{
Write-Host (-join ($Messages.CannotStartService," ",$serviceName)) -ForegroundColor Red
}
Catch [System.ServiceProcess.TimeoutException]
{
Write-Host (-join ($Messages.CannotStartService," ",$serviceName)) -ForegroundColor Red
}
}
}
}
catch [Exception]
{
Write-Host $_.Exception.Message -ForegroundColor Red
}
}
}
Write-Host $Messages.Done -ForegroundColor Yellow
}
else
{
Write-Host $Messages.UserNotInAdminRole -ForegroundColor Yellow
}
}
else
{
Write-Host $Messages.RequireLyncInstalled -ForegroundColor Yellow
}
}
Function Start-OSCLyncServicesOnEachServer { <# .SYNOPSIS Start-OSCLyncServicesOnEachServer can be used to start all the Lync Server services in topology except the Edge server. .DESCRIPTION Start-OSCLyncServicesOnEachServer is a function which can be used to start all the Lync Server services in topology except the Edge server. .EXAMPLE PS: Start-OSCLyncServicesOnEachServer .LINK Windows PowerShell Advanced Function http://technet.microsoft.com/en-us/library/dd315326.aspx #>if((Test-OSCCommonLyncInstalled)) { if((Test-OSCCommonIsEdgeServer)) { Write-Host $Messages.NoEdgeRun -ForegroundColor Yellow return } $me = whoami $currentUser = Get-CsAdUser -Identity $me$userName = $currentUser.SamAccountName $roles = Get-CsAdminRoleAssignment -Identity $userName$adminRole = $roles| Where-Object {$_-eq "CsAdministrator"} if($adminRole-ne $null) { $servers = @() #Returns information about the Edge Servers used in your organization.$edges = @(Get-CsService -EdgeServer) Get-CsManagementStoreReplicationStatus |ForEach-Object { $lyncServerName = $_.ReplicaFqdn foreach($edgein$edges) { if(-not($edge.Identity -like "*$lyncServerName")) { $servers+= $lyncServerName } } } foreach($serverin$servers) { Write-Host (-join $Messages.StartingServices,$server,$Messages.StartingServices2) -ForegroundColor Yellow $conn = Test-Connection -ComputerName $server-Count 1 -ErrorAction:SilentlyContinue if($conn-eq $null) { Write-Host (-join ($Messages.CannotConnect," ",$server)) -ForegroundColor Red } else { try { $services = Get-Service-ComputerName $server-DisplayName "*lync*"-ErrorAction SilentlyContinue $services|ForEach-Object { if($_.Status -eq "Stopped") { $serviceName = $_.DisplayName try { $_.Start() $_.WaitForStatus([System.ServiceProcess.ServiceControllerStatus]::Running,[TimeSpan]::FromSeconds(15)) Write-Host (-join ($serviceName," ",$Messages.IsStarted)) } catch [InvalidOperationException] { Write-Host (-join ($Messages.CannotStartService," ",$serviceName)) -ForegroundColor Red } Catch [System.ServiceProcess.TimeoutException] { Write-Host (-join ($Messages.CannotStartService," ",$serviceName)) -ForegroundColor Red } } } } catch [Exception] { Write-Host $_.Exception.Message -ForegroundColor Red } } } Write-Host $Messages.Done -ForegroundColor Yellow } else { Write-Host $Messages.UserNotInAdminRole -ForegroundColor Yellow } } else { Write-Host $Messages.RequireLyncInstalled -ForegroundColor Yellow } }
To obtain the detailed information about how to use the functions, run the following command to retrieve the help information:
Get-Help functionName –detailed
For example: Get-Help Show-OSCStoppedLyncServices -detailed
Example 1: Start all the Lync Server services for all computers in current topology.
Command: Start-OSCLyncServicesOnEachServer
Screenshot:

Example 2: Start all the Lync Server services for specific computer in current topology.
Command: Start-OSCLyncServicesByServer –ServerFQDN “ls-fe2.contoso.com”
Screenshot:
![]()
Example 3: Start all the Lync services for Edge server in current topology.
Command: Start-OSCLyncServicesOnEdge
Screenshot:
![]()
Example 4: Get all the stopped Lync Server services for all computers in current topology.
Command: Show-OSCStoppedLyncServices
Screenshot:

Windows PowerShell 2.0
Microsoft Lync Server 2010
Technical Resource:
Windows PowerShell Advanced Function
Administer Lync Server 2010 services from a remote Windows computer