Sunday, October 26, 2014

Lync Powershell Scripts

View the Status of Services Running on a Computer

Ø    To view the status of services running on a computer
To view the status of all the Lync Server services running on all your computers, use the following command:

Get-CsService | Select-Object Role, PoolFqdn | Sort-Object PoolFqdn, Role

To view the services running on a specific computer, use this command, replacing lync-001.msexchangequery.com with the fully qualified domain name of the computer to be checked:

Get-CsService | Where-Object {$_.PoolFqdn –eq "lync-001.msexchangequery.com"} | Select-Object Role, PoolFqdn | Sort-Object PoolFqdn, Role

For More Information

View Details About a Service

Ø  To view details for a service
To view detailed information for a particular Lync Server service or server role, use the Get-CsService cmdlet followed by the service Identity:

Get-CsService –Identity service:Registrar:lync-001.msexchangequery.com

To view detailed information for all your Lync Server services or server roles, call Get-CsService without any parameters:

Get-CsService

For More Information

Start or Stop Lync Server 2010 Services

Ø  To start or stop all Lync Server services on a computer
To start all the Lync Server services on a computer, use the Start-CsWindowsService cmdlet:

Start-CsWindowsService -ComputerName lync-001.msexchangequery.com


Note that the ComputerName parameter is not required if you are starting the Lync Server services on the local computer.

To stop all the Lync Server services on a computer, use the Stop-CsWindowsService cmdlet:

Stop-CsWindowsService -ComputerName lync-001.msexchangequery.com


Ø  To start or stop a specific service
To start a specific service, use the Start-CsWindowsService cmdlet along with the Name parameter:

Start-CsWindowsService –Name "RTCRGS" -ComputerName lync-001.msexchangequery.com

Use the Stop-CsWindowsService cmdlet to stop a specified service:

Stop-CsWindowsService –Name "RTCRGS" -ComputerName lync-001.msexchangequery.com

For More Information
The CsWindowsService Cmdlets at http://go.microsoft.com/fwlink/?LinkId=231028

Prevent Sessions for Services

Ø  To prevent new sessions for all Lync Server services on a computer
To prevent new sessions for all the Lync Server services on a computer use the following command:

Get-CsWindowsService | Stop-CsWindowsService -ComputerName lync-001.msexchangequery.com –Graceful

The Graceful parameter used with the Stop-CsWindowsService cmdlet ensures that all existing sessions will be honored but no new sessions will be allowed.

Ø  To prevent new sessions for a specific service
To prevent new sessions for a specific Lync Server service, use the following command:

Stop-CsWindowsService -Name "RTCRGS" -ComputerName lync-001.msexchangequery.com -Graceful

For More Information
The CsWindowsService Cmdlets at http://go.microsoft.com/fwlink/?LinkId=231028

Managing Users

Search for Lync Server 2010 Users
Ø  To search for one or more users
To search for a user based on the value of a Lync Server-specific attribute, use the Get-CsUser cmdlet and the Filter parameter. 

Get-CsUser -Filter {VoicePolicy -eq $Null}

To search for a user based on the value of a generic Active Directory attribute, use the Get-CsUser cmdlet and the LdapFilter parameter. For example, this command searches for all users who are members of the Finance department:

Get-CsUser -LDAPFilter "Department=Finance"

For More Information
·         21 User Information Cmdlets to Run Before You Die at http://go.microsoft.com/fwlink/?LinkId=231038

Add a New User to Lync Server 2010
Ø  To create a new Lync Server user
To enable a user to use Lync Server, use the Enable-CsUser cmdlet:

Enable-CsUser -Identity "Rakesh" -RegistrarPool "lync-001.msexchangequery.com" -SipAddressType SamAccountName  -SipDomain msexchangequery.com

The preceding command includes the SipAddressType and SipDomain parameters; this causes Lync Server to automatically create a SIP address for the user based (in this case) on the user's SamAccountName and the domain name litwareinc.com. Alternatively, you can use the SipAddress parameter to assign a specific SIP address to a user:

Enable-CsUser -Identity "rakesh" -RegistrarPool "lync-001.msexchangequery.com" –SipAddress "sip:rakesh@msexchangequery.com"

For More Information
·         21 User Information Cmdlets to Run Before You Die at http://go.microsoft.com/fwlink/?LinkId=231038
·         Enabling a User for Microsoft Lync Server 2010 at http://go.microsoft.com/fwlink/?LinkId=231040
·         Enabling a User for Microsoft Lync Server 2010 and Enterprise Voice at http://go.microsoft.com/fwlink/?LinkId=231043
·         The New Communications Server User Dialog at http://go.microsoft.com/fwlink/?LinkId=231044


Enable or Disable Users for Lync Server 2010
Ø  To disable or re-enable a previously enabled user account for Lync Server
To permanently disable a Lync Server user account

Disable-CsUser –Identity "rakesh"

Set-CsUser –Identity "Rakesh" –Enabled $False

·         Disable-CsUser at http://go.microsoft.com/fwlink/?LinkId=231046
·         Set-CsUser at http://go.microsoft.com/fwlink/?LinkId=231047

Finding all the people who have a telephone number set in Lync


Get-CsUser -Filter {LineURI -ne $NULL} | FT Name, LineURI

Change SIP domain for all users


$UserList = Get-CsUser 

foreach ($User in $UserList)

{

   $oldAddress = $User.SipAddress

   $newAddress = $oldAddress -replace "@olddomain.com", "@newdomain.com"

   Set-CsUser -Identity $User.Identity -SipAddress $newAddress

}



Setting the AD office phone number to the TelURI for all users


#Only need to add the AD Powershell instance once

Add-WindowsFeature RSAT-AD-Powershell
Import-Module ActiveDirectory

$users = Get-CSUser

Foreach ($user in $users)
{
   $Tel = $user.LineURI
   $Tel = $Tel.Replace("tel:", "")
   If ($Tel -ne "")
   {
      Set-ADUser -Identity $user.SAMAccountName -OfficePhone $Tel
   }
}

Enable All Users in a Group for Lync Enterprise Voice


#Uses existing office number in AD for Enterprise Voice

Import-Module ActiveDirectory

$Users = Get-ADGroupMember lync_group

ForEach ($User in $Users)
{
    Enable-CsUser $User.SamAccountName -RegistrarPool PHX-Lync15-FE.swc.local -SipAddressType EmailAddress
    $OfficePhone = (Get-CSADUser $User.SamAccountName).Phone
    $OfficePhone = $OfficePhone -replace "\D", ""
    Set-CSUser $User.SamAccountName -EnterpriseVoiceEnabled:$TRUE -LineURI "tel:+$OfficePhone"
}

Move All OCS Users Homed on a Specific Pool to Lync


Also sets conferencing policy and external access policy to automatic, rather than the legacy migrated OCS policies.  Replace items in bold with your environmental specifics.

get-csuser -OnOfficeCommunicationServer | Where {$_.HomeServer -eq "CN=LC Services,CN=Microsoft,CN=OCSPOOLNAME,CN=Pools,CN=RTC Service,CN=Services,CN=Configuration,DC=contoso,DC=com"} | Move-CsLegacyUser -Target LYNCPOOLFQDN -ExcludeConferencingPolicy -ExcludeExternalAccessPolicy -Confirm:$FALSE

Count How Many Users are on OCS and Lync
(Get-CsUser -OnOfficeCommunicationServer).Count
(Get-CsUser -OnLyncServer).Count

Get a List of All Lync-Enabled Users Along with Selected AD Properties


$ErrorActionPreference = 'SilentlyContinue'
Import-Module ActiveDirectory
$Output = @()

Foreach ($LyncUser in Get-CSUser -ResultSize Unlimited)
{
$ADUser = Get-ADUser -Identity $LyncUser.SAMAccountName -Properties Department, Title
$Output += New-Object PSObject -Property @{DisplayName=$LyncUser.DisplayName; Department=$ADUser.Department; Title=$ADUser.Title; SAMAccountName=$ADUser.sAMAccountName; SIPAddress=$LyncUser.SIPAddress; EVEnabled=$LyncUser.EnterpriseVoiceEnabled}
}

$Output | Export-CSV -Path .\Output.csv
$Output | FT DisplayName, Title, Department, SAMAccountName, SIPAddress, EVEnabled

Add Enterprise Voice Users to an AD Group


Foreach ($User in get-csuser -filter {EnterpriseVoiceEnabled -eq $TRUE})
{Add-ADGroupMember -Identity -Members $User.SamAccountName}
 


1 comment: