PShell

I have seen a lot of good posts and pages on commands for the Lync server and it's services. But as setting up the server and it's services is only one part of administering the the environment, I figured I wanted to collect some of the commands I find useful when doing the "everyday business".

Enable users for Lync based on OU
get-csaduser -filter {Enabled -ne $True} -OU "OU=Customer,DC=Domain,DC=COM" | foreach {
Enable-CsUser -identity $_.SamAccountName -RegistrarPool lyncpool.domain.com `
-SipAddressType EmailAddress -verbose}
Commands used: Get-CsUser, Enable-CsUser
--------------------------------------------------------------------------------------------------------------

Enable users for Lync based on Group
Get-ADGroup -Identity %GroupName% | Get-ADGroupMember -verbose | foreach {
Enable-CsUser -Identity $_.name -RegistrarPool %PoolFQDN% -SipAddressType %Yourselection%}
Commands used: Get-ADGroupGet-ADGroupMemberEnable-CsUser
--------------------------------------------------------------------------------------------------------------

Enable users for Enterprise Voice based on Group
get-adGroup -identity %Groupname% | get-adgroupmember | foreach {
Get-CsAdUser -Identity $_.Name | foreach {$sipit = $_.phone; $sipit = "tel:" + $sipit; `
set-csuser -Identity $_.Name -EnterpriseVoiceEnabled $true -LineURI $sipit -PassThru | `
Grant-CsVoicePolicy -PolicyName %POLICYNAME% -identity $_.Name}}
Commands used: Get-ADGroupGet-ADGroupMemberSet-CsUserGrant-CsClientPolicy

--------------------------------------------------------------------------------------------------------------

Clean up phone and mobile attributes
get-csaduser -OU %EnterOU% -Filter {windowsemailaddress -like *} | foreach {
$newOfficePhone = $_.phone;$newOfficePhone = $newOfficePhone -replace "[^0-9]"; `
$newOfficePhone = "+47" + $newOfficePhone; $newMobilePhone = $_.MobilePhone; `
$newMobilePhone = $newMobilePhone -replace "[^0-9]";  `
$newMobilePhone = "+47" + $newMobilePhone; set-aduser -identity $_.samaccountname `
 -Officephone $newOfficePhone -MobilePhone $newMobilePhone}
Commands used:get-csaduser, set-aduser, import-module
--------------------------------------------------------------------------------------------------------------

Clean up missing EXT in LineUri on users
$extSet = Get-CsUser -filter {lineuri -notlike "*ext*" -and lineuri -ne $null}
foreach ($user in $extSet){
$myURI = $user.lineuri
$myURI = $myURI + ";ext=" + $myURI.substring($myURI.length - "4") 
set-csUser -Identity $user.displayname -LineUri $myURI -verbose}
Commands used:get-csuser, set-csuser
--------------------------------------------------------------------------------------------------------------

If you're looking for a good blog post on one-liners for server management, you might want to take a look at Ståle Hansen's post on the subject.