You can sip coffee

And you can sip tea, too. But

You can't SipDomain.

 

You know what's interesting? Domains. (OK, so maybe they're not all that interesting. But we had to have something to act as the first sentence of this article.) For example, the other day the author of today's haiku received the following email from the US Department of Homeland Security:

 

This is to officially inform you that it has come to our notice and we have thoroughly completed an Investigation with the help of our Intelligence Monitoring Network System that you legally won the sum of $800,000.00 USD from a Lottery Company outside the United States of America.  

 

This made the author of today's haiku very happy, and for two reasons. First, of course, is the fact that he won $800,000 in a lottery he didn't even enter. Second, he was happy to see that the Department of Homeland Security was using its "Intelligence Monitoring Network System" to keep track of lottery winners. His tax dollars at work!

 

Still, the author was a tad bit skeptical. Yes, it made sense that the Department of Homeland Security would be monitoring lotteries around the world and notifying US citizens who won those lotteries; after all, who else would you expect to do a job like that? At the same time, however, the author is well aware that this is the age of the Internet scam. Because of that, and before he sent in his $300 Cashier's Check Conversion Fee, he checked the email address of the message. As it turned out, the mail was sent from the mai.mn domain; if you aren't familiar with all the top-level country code domains, MN is the country code for Mongolia. In other words, the US Department of Homeland Security is apparently headquartered in Mongolia. And, for good measure, they had his $800,000 deposited in a bank in Nigeria.

 

Which all made perfect sense to him. After all, if you were trying to pull an Internet scam by misrepresenting yourself as the US Department of Homeland Security you'd probably send your email from a US email address. The fact that the message came from Mongolia means that it must be real. As for the bank in Nigeria, well, who would know better about the recent spate of problems that have plagued US banks than the Department of Homeland Security? No wonder they picked a bank outside the US as a safe place to stash his winnings.

 

Domains play an important role in Microsoft Lync Server 2010, too: Lync Server can't function unless you have at least one valid SIP domain. And while we won't go into the details of how you go about setting this up, we will note that it's possible for your organization to have multiple SIP domains. Which leads to an obvious question: how do we keep track of all these SIP domains?

 

The answer – which might be equally obvious to regular readers of the daily haiku (yes, both of you) – is this: the CsSipDomain cmdlets. (Get-CsSipDomain, New-CsSipDomain, Remove-CsSipDomain, and Set-CsSipDomain.) For example, suppose you'd like to return information about all the SIP domains available for use in your organization. Well, that's easy enough:

 

Get-CsSipDomain

 

Or maybe you're ready to create a new SIP domain. That's almost as easy:

 

New-CsSipDomain -Identity fabrikam.com

 

As you can see, all you have to do is call New-CsSipDomain and specify the name of the new domain (fabrikam.com). It's that easy.

 

There are really only two things to keep in mind when working with SIP domains. First, you must always have one – and only one – default domain. You can always determine which SIP domain is your default domain simply by running this command:

 

Get-CsSipDomain | Where-Object {$_.IsDefault -eq $True}

 

What's important about that is that you cannot remove the default domain. Suppose you do create a new domain named fabrikam.com, and want to delete your old domain, litwareinc.com, which happens to be the default domain. This command is doomed to fail:

 

Remove-CsSipDomain –Identity "litwareinc.com"

 

Why? Because you can't remove the default domain. Instead, the first thing you need to do is make fabrikam.com the default domain (which is something we could have done when we created the domain in the first place; see the New-CsSipDomain help for more information):

 

Set-CsSipDomain –Identity fabrikam.com –IsDefault $True

 

Now you can delete the litwareinc.com domain.

 

Uh, well, maybe. Remember when we said there were two things you had to keep in mind when working with SIP domains? Well, here's the second thing: you cannot remove a SIP domain if you have any users who are using that domain as part of their SIP address.

 

That's what we said: how the heck are we supposed to know which users are using litwareinc.com in their SIP address? But, as usual, it's Windows PowerShell to the rescue:

 

Get-CsUser | Where-Object {$_.SipAddress –like "*@litwareinc.com"}

 

Good question: how did we ever survive without PowerShell?

 

Of course, while we now know which users are still using litwareinc.com in their SIP address we still have one problem: we have to remove or change those SIP addresses before we can delete the SIP domain litwareinc.com. But there's probably nothing that PowerShell can do to help us with that, is there?

 

Good heavens: how can you even think such a thing?!? Needless to say, PowerShell can do almost anything. For example, suppose all you want to do with your user's SIP addresses is replace @litwareinc.com with @fabrikam.com. If that's the case, then this little script should do the trick:

 

$users = Get-CsUser | Where-Object {$_.SipAddress –like "*@litwareinc.com"}

 

foreach ($user in $users)

    {

        $sipAddress = $user.SipAddress

        $sipAddress = $sipAddress.Replace("@litwareinc.com","@fabrikam.com")

        Set-CsUser –Identity $user.Identity –SipAddress $sipAddress   

    }

 

So what are we doing here? Well, to begin with, we use Get-CsUser to grab a collection of all the users who have a SIP address that ends in @litwareinc.com; we then set up a foreach loop to loop through all the users in that collection. Inside the loop, we grab the SIP address of the first user (for example, sip:kenmyer@litwareinc.com) and store that value in a variable named $sipAddress. That brings us to this line of code:

 

$sipAddress = $sipAddress.Replace("@litwareinc.com","@fabrikam.com")

 

Here we're simply taking the value stored in $sipAddress and replacing any instance of @litwareinc.com with this: @fabrikam.com. In other words, a SIP address that started out like this:

 

sip:kenmyer@litwareinc.com

 

Is going to end up looking like this:

 

sip:kenmyer@fabrikam.com

 

See what we did there? All that's left is to then use Set-CsUser to change the user's SIP address to the new fabrikam.com address:

 

Set-CsUser –Identity $user.Identity –SipAddress $sipAddress

 

See? We told you PowerShell can do almost anything.

 

That's all we have time for today; we have to go check the mail and see if our $800,000 has arrived yet. And what does the author intend to do with all that money? Not much; he'll probably just toss it on the pile with all the rest of his money. After all, when you're a technical writer at Microsoft, well, what's another $800,000? If you know what we mean.