Tuesday, August 28, 2012

Get the Email Address of the Current User

Ran into an issue with a scheduled job that was sending emails.  Our SMTP host does not allow messages where the FROM address does not belong to the user submitting the messages (so I can’t spoof my boss’s email).  The script I was scheduling will run on different servers using different credentials.  V1 of my script hard coded the FROM address, and those messages were being rejected by our SMTP host.  Instead of updating the scripts so that the FROM address matched the credentials of the Scheduled Job, I used this script snippet to discover the email address:


### Get the Email address of the current user



    ### Get the Distinguished Name of the current user

    $userFqdn = (whoami /fqdn)


    ### Use ADSI and the DN to get the AD object

    $adsiUser = [adsi]("LDAP://{0}" -F $userFqdn)


    ### Get the email address of the user

    $senderEmailAddress = $adsiUser.mail[0]




    Throw ("Unable to get the Email Address for the current user. '{0}'" -f $userFqdn)



Tuesday, August 14, 2012

FIM Service PowerShell Module Samples

Finally had time to catch up on some documentation and added some samples to the documentation for the FIM Service PowerShell module.

These samples are meant to be more scenario based than the examples that are included in the function examples (and there are lots of those too BTW!).

Monday, August 13, 2012

Hidden Gem: FimSyncPowerShellModule.psm1

The interesting player statistic for me this year has been the low number of blog posts and the high number of CodePlex check-ins.  This seems to demonstrate that I am talking less and sharing more.  The catalyst here has been PowerShell.  I’ve become a huge fan of building tools with PowerShell, and perversely enjoy it.  It affords IT Pros like me the opportunity to produce and share useful code without TOO much serious development effort.

The past few years have been very busy and I’ve been able to post some very useful PowerShell functions.  Hopefully I’ll be able to catch up with documentation soon enough, because I don’t think staring at the script is the best way to learn how to use somebody else’s functions.  Luckily I’ve been pretty good about providing comment-based help as I’ve been posting the functions, so generating the documentation is actually quite simple.

This first batch of examples contains some really cool functions that taught me how to make use of some really cool features in PowerShell that allowed them to be rather compact.  Reading through the module you can probably tell that I’ve learned some lessons as I wrote it.  Many of the functions have been re-written a few times, and there are many more functions that are just too knarly to post because I haven’t found a way to make them simple enough to share.

Anyhow, here is the first batch of documentation pages:

Updated FIM PowerShell WF Documentation

For those willing to RTFM, I’ve made some updates to the documentation for the FIM PowerShell Activity.  I’ve been using this thing exhaustively in my deployments, and have even delivered training on it at the TEC conference so figured it was time to lower the bar a little by providing some documentation.


Some highlights include:

  • Accessing FIM Request details from your PowerShell script
  • Adding items to the FIM WorklowDictionary from your PowerShell script
  • Saving the Request details to XML
  • Dumping the Request details to the Event Log

Hey, Where’d the PowerShell Deep Dive Go?

A little bummed that the PowerShell Deep Dive no longer appears on the TEC Europe site.  I’ve been lucky enough to attend a lot of the sessions from the Deep Dive and was really impressed by the energy and enthusiasm, not to mention the great showing from the PowerShell product group and PowerShell community.  Looking forward to seeing where it pops up next!