Monday, July 1, 2013

Creating Additional SMTP Addresses For Exchange Users

I recently had to add an additional SMTP Address for all the users in my domain. I wrote this quick script that made it a no brainer:

<#
.NAME
    Append-EmailAddresses.ps1
.SYNOPSIS
    This script adds a new smtp address of first.last@exchange.yourdomain.com
    to all email users that have an @yourdomain.com email address
.DESCRIPTION 
  Versions
    1.0 - 12/21/2011 Initial release
.LINK
    http://unicomsta.blogspot.com/
.EMAIL
    sean.mcnamara@live.com
.EXAMPLE
    .\Append-EmailAddresses.PS1
.INPUTS
    None. You cannot pipe objects to this script.
#>

$mailboxes = Get-Mailbox -resultsize unlimited -RecipientTypeDetails UserMailbox"
foreach ($mailbox in $mailboxes)
{
  
$newaddress = $mailbox.windowsemailaddress -replace '@yourdomain.com' , '@exchange.yourdomain.com'

$mailbox.EmailAddresses += $newaddress

Set-Mailbox -Identity $mailbox.alias -EmailAddresses $mailbox.EmailAddresses
}

Wednesday, April 17, 2013

Getting and Using Your IP Address in Powershell

UPDATE: 1/14/2015: PowerShell now has built in cmdlets to handle this. Try

Get-NetIPAddress




Getting an IP Address from a machine is something we need to do often, for many reasons. Typically, you would employ the CLI tool IPCONFIG to get it, and if you wanted to quickly get just the IP Addresses for your machine, you might use:

ipconfig -all | findstr IPv4

The output of which would look like:

C:\>ipconfig -all | findstr IPv4
   IPv4 Address. . . . . . . . . . . : 129.168.34.233(Preferred)
   IPv4 Address. . . . . . . . . . . : 129.168..93.194(Preferred)


Which is fine but doesn't give you the flexibility to use that information within a powershell script to do other things, so where's the fun in that? Also, getting it with powershell is a necessary skill for anyone that administers servers (at least to my way of thinking). I wrote the following code and saved it as "Get-IpAddress.ps1" on all my machines. It gives me the output I want in the format I want for most of my quick needs:

$strComputer ="."
$colItems = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace "root\CIMV2" | where{$_.IPEnabled -eq “True”}

Write-Host " "
Write-Host "********************************************"
Write-Host " "
foreach($objItem in $colItems) {
     Write-Host "Adapter:" $objItem.Description
     Write-Host "         DNS Domain:" $objItem.DNSDomain
     Write-Host "         IPv4 Address:" $objItem.IPAddress[0]
     Write-Host "         IPv6 Address:" $objItem.IPAddress[1]
     Write-Host " "
      }
Write-Host "********************************************"
Write-Host " "

I can then run it from any powershell prompt by invoking the script. The output of the above script is:

PS C:\scripts> .\Get-IpAddress
********************************************

Adapter: Intel(R) Centrino(R) Advanced-N 6205
         DNS Domain: global.mydomain.com
         IPv4 Address: 192.10.93.194
         IPv6 Address: fe99::68a8:5ac:89b2:ffff


Adapter: Intel(R) 82579LM Gigabit Network Connection
         DNS Domain: global.mydomain.com
         IPv4 Address: 192.168.34.233
         IPv6 Address: fe99::d191:bbb1:a067:ffff
********************************************

PS C:\scripts>
 
Now, the basis of the script can be used as a function in other scripts. Say, for example you wanted to use a script to determine whether you were working from the office, home or a remote location at start-up and act on the location by starting or not starting certain applications. You might want to, say, start outlook and lync only if you're in the office at start-up, and leave them offline if you're working from home, at least until you've had the chance to VPN in (Yes, some companies will not allow Outlook Anywhere or Lync Edge Connections or split tunneling). You could accomplish this with a script that looks something like this:

Friday, March 15, 2013

List A User's Response Group Memberships

We just had an issue where a response group in Lync was not working properly. While troubleshooting, we discovered that the user to whom the response group pointed had recently been married and had her name changed. Per normal process, her AD account, email address and SIP name were changed to her new name. This caused an issue with the response group, however. Since there was a gap in the process, and we had no procedure in place for checking the user’s membership in response groups, the group was trying to transfer a call to a now non-existent SIP address. So, that means whenever we change an account we must know if the user is Enterprise Voice enabled, and if they are, we must also know if they belong to any response groups. Unfortunately, there is no clean way to find that membership in the Lync Control Panel. You would have to open each response group and look at its membership one at a time to see if the user was a member. To get around this, you’ll have to RDP into a Lync  Server and open a Lync Powershell session and enter the following command:

get-csrgsagentgroup | Where-Object {$_.AgentsByUri -like "sip:first.last@spx.com"} | Select name

See the example below to illustrate what it looks like and what the results would be:
This will give you a list of response groups the user is a member of. You can then make the appropriate changes to the groups, if any.

Thursday, August 9, 2012

Enabling users for Lync Enterprise Voice

I am now piloting Lync Enterprise Voice for my company, and we will be enabling many users moving forward. I have written the following script to:
  1. Move users to a "Branch" Pool
  2. Enable them for Voice
  3. Grant a voice policy
The script is meant to be run, eventually, by local IT at the branch location. It takes input from a .csv file structured like:

LineURI,Name,ADUSERNAME
tel:+11112345678;ext=5678,Jon Smith,jsmith
tel:+11112347485;ext=7485,Nasir Patel,npatel
tel:+11112347518;ext=7518,Tom Jones,tjones


You can tailor the LineURI as appropriate for your organization.

The script, when launched, asks for the target pool, the file with the information and the voice policy to be granted:




That's all you need to do. Well, that and then enable them in whatever voicemail solution you are employing...

The code is as follows. I will make it more elegant as time allows.

<# 
.SYNOPSIS 
  Queries admin for Pool, Input File and Voice Policy for the users. Then
  reads info in Input file, moves users to appropriate pool, enables Enterprise
  Voice for them, and grants the entered Voice Policy.

.NOTES 
    Version           : 1

      Lync Version  : 2010 through CU6
    Author(s)      : Sean William McNamara (
sean.mcnamara@spx.com)
    Dedicated Post  :
http://unicomsta.blogspot.com/
    Disclaimer     : Test thoroughly and use at your own risk. If you don't test it, and you break stuff, it isn't MY fault.
   
.LINK 
    http://unicomsta.blogspot.com/2012/08/enabling-users-for-lync-enterprise-voice.html

.EXAMPLE
  .\Enable-EvUsers.ps1
#>
#initialize variables
$poolfqdn = read-host "Enter new pool FQDN to move users to "
$InputFileName = read-host "Enter filename for user data "
$VoicePolicy = read-host "Enter Voice Policy Name "


#read data for Accounts
$AccountData = Import-Csv $InputFileName

#move users to correct registrar pool
foreach ($item in $AccountData)
{ write-host -fore yellow "Moving" $item.NAME "... "
  move-csuser -identity $item.ADUSERNAME -target $poolfqdn -confirm:$false
}

write-host
write-host -fore green "Move completed"
write-host
#enable EV and set URI

foreach ($item in $AccountData)
{ write-host -fore yellow "Enabling Voice for " $item.NAME "... "
  Set-CsUser -Identity $item.adusername -EnterpriseVoiceEnabled $true -LineURI $item.LineURI
}

write-host
write-host -fore green "Enterprise Voice Enabled"
write-host

#grant Voice Policy
foreach ($item in $AccountData)
{ write-host -fore yellow "Granting Voice Policy "$VoicePolicy" to " $item.NAME " ... "
  Grant-CsVoicePolicy -Identity $item.adusername -PolicyName $VoicePolicy
}

write-host
write-host -fore green "Voice Policies Granted"
write-host

Tuesday, July 17, 2012

View Lync Client Configuration

You can easily view the configuration information of the Lync 2010 client by following these simple steps.
  • Hold the Control key down while right-clicking the green Lync client icon in the notification area.

  • This will enable the Configuration Information menu option. Click it and you will see a pop-up window that displays all the Lync 2010 configuration information for the client.

Trouble Transferring and Answering Calls from Lync Attendant Console

At one of my sites where Lync has been deployed as a replacement for a PBX I ran into an issue with the receptionist being able to answer and or transfer calls from the PSTN. Calls would come in, and about 30% would be problematic. Some, she couldn't answer at all, others, would either drop when she tried to transfer them, or would connect only after 45-60 seconds of silence, by which time, the caller would assume the call had been dropped and hang up. As you can imagine, this was having a significant impact on our ability to do business.

I researched online, and didn't really find any reasonable explanations or solutions. So, I opened as case with Microsoft Premier Support, and as we were working through testing, pulling logs from the SBA, Front End Servers and the receptionist's Attendant Console, we determined that what was happening was that the SIP REFER method was failing. Information on what the SIP REFER method does can be found at: RFC 3515 - SIP Refer Method..

After some more research, I discovered that SIP REFER is enabled by default in Lync, and the Gateway we have deployed, the NET UX 2000, does not support SIP Refer. I found this article on NET's website that explains how to disable SIP REFER, and as a result, Media Bypass: Disable Refer Support (required for Transfer).

The Microsoft article on this is found here: Configure a Trunk Without Media Bypass. The MS article lacks a great deal of information, and barely mentions the SIP REFER option.