• Haiku #100

    100 haikus?

    Seems like only yesterday

    We had 99.

     

    Hey, everyone, and welcome to the Lync Server PowerShell haiku of the day. (Note that this is the original Lync Server PowerShell haiku of the day, and not one of the many imitation Lync Server PowerShell haiku sites springing up all over the Internet.)

    Today is a truly momentous occasion for those of us here at the Lync Server PowerShell blog: today marks the 100th edition of the haiku of the day! At the risk of patting ourselves on the back, we'd like to take a few minutes to read all the congratulatory emails and telegrams that have been pouring in throughout the morning:

     

     

    OK, that didn't take quite as long as we thought it would. Of course, the Internet is probably a bit overloaded at the moment. The next time they have a Royal Wedding we'll ask them to please schedule it for a day when we don't have a Lync Server PowerShell haiku. The Royal Wedding and the 100th Lync Server PowerShell haiku, all on the same day? That's just too much excitement for one day.

     

    Note. If you happened to miss any of the previous 99 haikus, just head to the Haiku of the Day Archive, they’re all there.

     

    History buffs out there might be interested to know that the Lync Server PowerShell haiku of the day was originally conceived by the Danish physicist Niels Bohr way back in October of 1913. At the time, Bohr was ridiculed by his fellow scientists, in part because there was no such thing as Windows PowerShell and no such thing as Microsoft Lync Server. Those of us who believed in Bohr and his vision refused to give up, however, and now, 98 years later, we have the fruit of our labors: the 100th edition of the Haiku of the Day!

     

    Note. Ninety-eight years and this is the best we could come up with? Come on, give us a break: if we were actually capable of doing things, is this what you think we'd be doing?

     

    At any rate, on with the show. For our 100th edition of the haiku of the day we did what we always we do when it comes time to pick a topic: we rolled the dice, and we came up with the Lync PowerShell noun of the day. Ladies and gentlemen: CsPresence!

     

    Note. As you probably know, there are approximately 202 Lync Server PowerShell nouns. When we say we "rolled the dice," does that mean that Microsoft has a pair of dice in which each die has 101 sides? Well, we’re not really at liberty to say this, but: yes. It's a project that the research department has been working on for several years now although, for some reason, they'll deny it if you ask them about it

     

    As it turns out, there's only one cmdlet that falls into the CsPresence family: Test-CsPresence. That means that today's article should be an easy one to write up.

     

    Note. Could that be the reason we chose CsPresence, the fact that we really didn't feel like doing much this morning? Let's put it this way: if you ask about it, we'll deny it.

     

    The Test-CsPresence cmdlet is designed to do one thing and one thing only: it checks to see if two users can log on to Lync Server and exchange presence information. The cmdlet will try to log the two users on to the system and then see if those users can exchange presence information. If they can, you'll get back something that looks like this:

     

    TargetFqdn : atl-cs-001.litwareinc.com

    Result     : Success

    Latency    : 00:00:00.3227016

    Error      :

    Diagnosis  :

     

    And if those two users can't exchange presence information? Then you'll get back results like these:

     

    TargetFqdn : atl-cs-001.litwareinc.com

    Result     : Failure

    Latency    : 00:00:00

    Error      : Presence notification is not received within 25 secs.

    Diagnosis  :

     

    At that point, you can re-run the test, this time adding the Verbose parameter to ensure that you get a blow-by-blow account of everything the cmdlet tries to do. For example, in our test that failed, the Verbose parameter showed us that both users were able to log on and configure themselves to receive presence information from one another; however, our first user was unable to actually publish his presence information. Why? Well, to be honest, we're not sure; we didn't bother to investigate this in full. However, we re-ran the test using a different user and everything worked fine. We then put the original user back in, and encountered the same problem we encountered before. If nothing else, that helps us narrow things down a bit: as near as we can tell, the problem lies not with the system itself but with that one user account.

     

    Ah, good question: how did we run these tests? Well, if you have configured health monitoring configuration settings for a Registrar pool all you need to do is run a command like this one:

     

    Test-CsPresence –TargetFqdn atl-cs-001.litwareinc.com

     

    If you don't specify any user accounts, Test-CsPresence will automatically use the two health monitoring accounts configured for the pool and run its checks using those accounts.

     

    Note. If you have no idea what health monitoring configuration accounts are you should probably take a look at this haiku. Which, interestingly enough, was haiku number 50. Did we plan things so that haiku 100 would refer back to another major milestone, haiku 50? If it makes us sound like we know what we're doing then yes, we did plan that.

     

    Alternatively, you can also run this check using any two Lync Server-enabled user accounts; the only catch is that you have to supply the user name and password for each of those accounts. Assuming that you have that information, then commands like these will let you determine whether or not a pair of real, live users can exchange presence information:

     

    $cred1 = Get-Credential "litwareinc\pilar"

    $cred2 = Get-Credential "litwareinc\kenmyer"

     

    Test-CsPresence -TargetFqdn atl-cs-001.litwareinc.com -SubscriberSipAddress "sip:pilar@litwareinc.com" -SubscriberCredential $cred1 -PublisherSipAddress "sip:kenmyer@litwareinc.com" -PublisherCredential $cred2

     

    All in all, a pretty handy little cmdlet to have at your disposal.

     

    Before we go we'd like to acknowledge a few other 100th anniversaries:

     

    ·         The Southeastern Massachusetts YWCA

    ·         The state of Massachusetts, celebrating the first law to ever make it illegal to sell or possess cannabis without a prescription

    ·         The Evansville Bar Association

    ·         International Women's Day

    ·         Washington High School in Milwaukee, WI


    Congratulations to all of you!

     

    Oh, and thanks for acknowledging our anniversary. Sigh …

     

     

     

  • April Wrap-Up…and Haiku #100

    The old saying is “March comes in like a lion, goes out like a lamb.” Well, that’s one ferocious lamb because April has been roaring away here in Redmond. Another saying is “April showers bring May flowers.” If that one’s true you’ll be able to spot the Seattle area from space – it’s that very colorful spot over there on the west coast of North America.

     

    Has anyone ever counted the number of words Seattleites have for “rain?” Showers, mist, drizzle, …. Does anyone really know what the difference is between rain and showers?

     

    Well, it’s been raining (or showering) haikus here at the Lync Server PowerShell blog. (How’s that for a segue?) And tomorrow, Friday, April 29, 2011, marks the publishing of the 100th Lync Server PowerShell Haiku. To celebrate we’re going to…well, we’re going to publish the 100th Lync Server PowerShell haiku.

     

    Do we know how to party here or what?

     

    And, in case you missed anything, here’s what else happened in April:

     

    No Conferencing Policy is an Island: Per-Organizer Settings vs. Per-User Settings

    Export to Excel

    How to Export Lync Contacts to Excel

    Export Lync Contacts to Excel (script only)

    Simultaneously Assigning a Policy to Multiple Users

    How to Cheat at Sporcle

     

    And of course the One of These is Not Like the Others challenge is still going on. Plus, we didn’t get to 100 without doing to first 99: find all the haiku’s in the Haiku Archive.

     

    There’s more coming in May, so stay tuned.

     

    Thanks for joining us. We’re going to go watch all those flowers come up.

     

  • How to Cheat at Sporcle

    By now we hope you've had the chance to try your hand at our initial contribution to Sporcle, the online site for "mentally stimulating diversions." If you managed to solve the puzzle, all we can say is this: Congratulations on a job well done! But what if you weren't able to solve the puzzle? What then?

     

    Well, no doubt your mom would say something like, "Well, if you want to succeed at something you just need to try harder." And, to be perfectly honest, we tend to agree with mom on this one … well, except for the part about "trying harder," of course. After all, trying harder is, well, hard. Isn't there an easier way to solve this puzzle? Some way, like, say, cheating ….

     

    Fortunately for all of us (or at least for those of us who don't want to try harder), it turns out that it is possible to cheat at the Lync Server Sporcle puzzle. If you haven't had a chance to glance at the puzzle just yet, the whole thing looks a lot like this:

     

     

    See the letters listed in the First Letter column? As it turns out, there's at least one Lync Server PowerShell verb that starts with each of the letters that appear in that First Letter column. For example, you see the letter D listed under First Letter. Why? Because there's at least one Lync Server verb that starts with the letter D. So how come you don't see the letter Z listed anywhere? You got: because there aren’t any Lync Server verbs that start with the letter Z. In order to solve the puzzle you just have to start typing in verbs; if you get one correct that verb will be put in the appropriate spot:

     

     

    OK, so all we need to do is start typing in verbs, huh? Well, we know that there's at least one verb that starts with the letter A. OK, let's see: Abrogate? Ascertain? Ascend?

     

    Hmmm, this isn't as easy as it looks …. In fact, it would be a lot easier if I didn't have to think about this, but instead already had a list of the answers sitting right in front of me.

     

    Apparently we were thinking the same thing:

     

    $letters = "A","B","C","D","E","F","G","H","I","J", `

        "K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"

     

    foreach ($x in $letters)

        {

            $verbs = Get-Command -Module Lync |

                Where-Object {$_.Verb -like "$x*"} | Select-Object Verb

            $count = ($verbs | Measure-Object).Count

            if ($count -ne 0)

                {

                    $verbs | Get-Random -Count 1

                }

        }

     

    The preceding script is designed to help you solve the Lync PowerShell Verbs puzzle. How does it do that? Well to begin with, the first line in the script creates an array named $letters; as the name implies, this array contains each of the 26 letters found in the English alphabet.

     

    After we create the array, we set up a foreach loop that loops through each item in that array; that is, through each letter in the alphabet. Inside the foreach loop, the first thing we do is run this command:

     

    $verbs = Get-Command -Module Lync | Where-Object {$_.Verb -like "$x*"} | Select-Object Verb

     

    What we're doing here is using the Get-Command cmdlet to retrieve a collection of all the Lync Server cmdlets (the Module parameter enables us to limit the retrieved data to just the Lync Server cmdlets). That collection is then piped to the Where-Object cmdlet, which picks out only those cmdlets where the Verb property begins with a specific letter. Which specific letter? Well, as we noted, the foreach loop is iterating through all the items stored in the array $letters. That means that, the first time through the loop, the loop variable $x is set to the value of the first item in the array: A. As a result, the first time we run through the loop we'll be looking for Lync Server verbs that start with the letter A. The second time we run through the loop, we'll be looking for Lync Server verbs that start with the letter B. Etc., etc.

     

    In other words, the first time we run through the loop we'll grab information for all the Lync Server cmdlets whose Verb starts with the letter A. We then pipe that data to the Select-Object cmdlet, which extracts just the Verb values from that huge mass of data.

     

    Note. Do we really need to do that? No, not really. However, Get-Command does return a lot of information about each cmdlet: Verb; Noun; DLL; Parameters; ImplementingType; etc. Because we care about only the Verb we decided to make things easier for everyone by getting rid of everything that isn't a Verb.

     

    OK, let's pretend that Abrogate, Ascertain, and Ascend really are Lync Server PowerShell verbs. In that case, the variable $verbs will contain three items:

     

    ·         Abrogate

    ·         Ascertain

    ·         Ascend

     

    Note. If there’s more than one cmdlet that begins with the same verb, you’ll get multiple instances of that verb. For example, if there were cmdlets named Ascertain-CsDialPlan and Ascertain-CsVoiceNormalizationRule, your list would look like this:

     

    Abrogate

    Ascertain

    Ascertain

    Ascend

     

    For the purposes of this script it doesn’t matter, we’re just going to randomly pick one anyway. But if you’d like to get only one instance of each verb, add the –Unique parameter to the end of your Select-Object command, like this:

     

    $verbs = Get-Command -Module Lync | Where-Object {$_.Verb -like "$x*"} | Select-Object Verb –Unique

     

     

    Got that? Good. Next, we use this line of code to count the number of items in the array $verbs:

     

    $count = ($verbs | Measure-Object).Count

     

    Why do we do that? Well, we already know that some letters don't have even one corresponding Verb; for example, there aren't any verbs that start with the letter X. Therefore, what we do with this line of code is count the number of verbs retrieved for the current letter. If the Count is 0, that means we don't have any verbs. Consequently, we skip that letter and go to the next item in the array. That's what will happen when we try the letter Q. There aren't any verbs that start with Q, which means that the Count will be 0. Which means, in turn, that we'll just drop the letter Q like a hot potato and then move on to the next letter in the array.

     

    But what if the Count isn't 0? Well, that means that we have at least one verb that starts with the current letter. (For example, at least one verb that starts with the letter A.) If a letter has at least one corresponding verb we then run this command:

     

    $verbs | Get-Random -Count 1

     

    What's going on here? Here we're simply taking our collection of verbs (Abrogate, Ascertain, Ascend) and piping that collection to the Get-Random cmdlet. We're then asking Get-Random to randomly select one of those verbs (-Count 1) to display onscreen. As a result, we'll see something similar to this onscreen:

     

    Ascertain

     

    So what does that mean? That means that we can type Ascertain into the Sporcle puzzle and be sure of getting at least one answer correct. (We can’t, really. Ascertain was just an example. You’ll have to run the script to find the real answers.) After all, Ascertain won't show up onscreen unless it happens to be a valid Lync Server PowerShell verb.

     

    See how much easier it is to cheat? Makes you wonder why people don't do it more often, doesn't it? Needless to say, we heartily condone, encourage, endorse, and otherwise recommend cheating whenever you think you can get away with it!

     

    Note. Um, on the advice of our management, and in consideration of all the many young children out there who regularly read the Lync Server PowerShell blog, we do not condone, encourage, endorse, or otherwise recommend cheating of any kind.

     

    Well, unless you know for sure that you'll never get caught. In that case ….

     

    Anyway, after we've printed out a verb for the letter A (assuming that there is a verb for that letter) we then loop around and repeat the process for the letter B. By the time we're finished, we should see 14 verbs onscreen, 14 verbs that match up quite nicely with the answers needed to successfully solve the Lync PowerShell Verbs puzzle.

     

    And here some of you thought that Windows PowerShell could never be put to any practical use. Now you know better!

     

  • Haiku #99

    Nine million turkeys

    Can be wrong: Make use of the

    TimeRange cmdlet.

     

    Yesterday evening, when the author of today's haiku got out of his car, he glanced up at the sky and had a raindrop fall into his half-opened mouth. (Yes, those of us who work here at Microsoft do lead interesting lives, don't we?)

     

    To be honest, that wasn't a big deal, nor was it the worst thing he ever had fall into his mouth (for now we'll ignore the okra that he … willingly … ate). A few years ago, he was riding his bike, mouth half-opened again, when a bee flew through the opening and stung him on the inside of the mouth. That was not a whole heck of a lot of fun although, truth be told, it was still better than the okra.

     

    Note. Does this suggest that maybe the author of today's haiku should keep his mouth closed more often? Interestingly enough, his wife has been telling him that very thing for years now!

     

    At any rate, when the raindrop fell into his mouth, the first thing the author of today's haiku thought about was turkeys. According to American folklore, turkeys are so dumb that, when it starts to rain, they stare up at the sky, mouths half-open in fascination. In fact, turkeys are so fascinated by the rain that they continue to stare up at the sky, their mouths fill up with water, and they drown.

     

    So do turkeys really drown in the rain? According to "scientists," no, they don't. However, the author of today's haiku wasn't going to take any chances, so he stopped staring at the sky and immediately went inside.

     

    Note. The author of today's haiku is not a scientist. (He's not much of a haiku writer, either, but that's a different story.) On the other hand, there are times when his unfenced backyard resembles a game preserve: he's had every kind of animal from snakes to rabbits to raccoons to squirrels to coyotes in his backyard. And yet, he's never had a turkey in his backyard, never. (He's had several in his oven, but that, too is another story.) It rains all the time in Seattle, and he's never seen a turkey in Seattle. Could that be because all the Seattle turkeys have already drowned? Just a thought …

     

    Although the notion that turkeys can actually drown in the rain is still being debated, there's no doubt that turkeys are incredibly dumb animals. How can the author of today's haiku say that? Because of this: even scientists agree that no turkey has ever (ever) used the New-CsRgsTimeRange cmdlet.

     

    We kid you not.

     

    So why don't turkeys use the New-CsRgsTimeRange cmdlet? That's a good question, and one that even our crack research team here at the Lync Server PowerShell blog has been unable to answer. About all we can tell you at this point in time is that New-CsRgsTimeRange is a must-have cmdlet when you are configuring hours of business for a Response Group workflow. If you aren't familiar with hours of business, those are simply, uh, the hours of business for a workflow, the days and times when agents are available to answer calls. For example, suppose your help desk is staffed from 9:00 AM to 5:00 PM Monday through Friday. In that case, you need to assign those days and times to the workflow.

     

    And you can't assign those days and times without first using the New-CsRgsTimeRange cmdlet. Fortunately, New-CsRgsTimeRange is a pretty simple little cmdlet to use: all you have to do is specify an opening time and a closing time, like so:

     

    $weekdayHours = New-CsRgsTimeRange –OpenTime "9:00" -CloseTime "17:00"

     

    Two things to note here. First, you do need to use the 24-hour clock when setting opening and closing times; as you can see, we set the OpenTime to 9:00 and the CloseTime to 17:00. Suppose we tried using US time settings instead:

     

    $weekdayHours = New-CsRgsTimeRange –OpenTime "9:00 AM" -CloseTime "5:00 PM"

     

    If we do that, our command will fail and we'll get back this error message:

     

    New-CsRgsTimeRange : Cannot bind parameter 'OpenTime', Cannot convert value "9:00 AM" to type "System.TimeSpan". Error: "Input string was not in a correct format."

     

    Second, notice that we save the results of running New-CsRgsTimeSpan to a variable ($weekdayHours). Why? Because if we didn't, that time range would disappear as soon as the command finished running. That's important to note: you can't permanently save a time range. That means that every time you create new hours of business you'll need to create a time range to use with those new hours.

     

    After you've created your new time range you can then use that range with either the New-CsRgsHoursOfBusiness or the Set-CsRgsHoursOfBusiness cmdlet to configure actual hours of business; after that, those business hours can then be assigned to a workflow. Without going into any detail, here's a command that sets up a new set of business hours called the Help Desk Business Hours:

     

    New-CsRgsHoursOfBusiness -Parent Service:ApplicationServer:atl-cs-001.litwareinc.com -Name "Help Desk Business Hours" -MondayHours1 $weekdayHours -TuesdayHours1 $weekdayHours -WednesdayHours1 $weekdayHours  -ThursdayHours1 $weekdayHours  -FridayHours1 $weekdayHours

     

    If you take a minute to look at that command, you'll see that we have a parameter for each weekday, Monday through Friday. For each of those weekdays, we've then set the hours to the variable $weekdayHours, the variable we created using New-CsRgsTimeRange. And then, just to ensure we have a happy ending today, we could then assign these business hours to a workflow:

     

    $businessHours = Get-CsRgsHoursOfBusiness service:ApplicationServer:atl-cs-001.litwareinc.com -Name "Help Desk Business Hours"

    $y = Get-CsRgsWorkflow Service:ApplicationServer:atl-cs-001.litwareinc.com -Name "Help Desk Workflow"

    $y.BusinessHoursId = $businessHours.Identity

    Set-CsRgsWorkflow -Instance $y

     

    That's all there is to it.

     

    Incidentally, the author of today's haiku has learned that a researcher at Oregon State University believes that turkeys really do occasionally stop and stare blankly into space for a minute or so. However, this isn't because they are dumb, but because they suffer from a genetic disorder known as tetanic torticollar spasms. In looking this up (hey, it's better than working right?) the author of today's haiku learned that torticollis (also known as "wry neck") is a malady in which the head is twisted to one side, with the chin pointing up; tetanic refers to a muscular contraction. So do tetanic torticollar spasms explain why the author of today's haiku often walks around with his mouth half-open, staring blankly into space? It does now!

     

  • Not Like the Others: Challenge 15: Hint

    So you say you need a hint for this week’s Lync Server PowerShell Challenge, do you? Well, let me put you on hold for a second.

     

    What’s that? We did give you a hint. No, really, we did. Let me put you on hold for a second.

     

    No, we are not just stalling for time and hoping that you’ll go away; we gave you a hint. Let me put you on hold a second.

     

    Oh come on, don’t go away mad. Here: let me put you on hold a second.

     

    Oh, well. At least now we can go back to figuring out who is on first ….

     

    Challenge Home