Get-NextBusinessDay

I had a need to calculate the next business day in a script I was writing.

Pretty short and sweet.

 

Function Get-NextBusinesDay {
param($days)
$date = get-date
$newDate = $date.AddDays($days)
switch ($newDate.DayOfWeek)

    {
       "Saturday" {$newDate = $newDate.AddDays(2); $newDate}
       "Sunday"   {$newDate = $newDate.AddDays(1); $newDate}
       Default {$newDate}
    }
}

 

image

Seattle Script Club is Back!

James Brundage, Craig Martin, and I are happy to announce that after several years of hiatus, the Seattle Script Club is starting once again.

Script Clubs have been a great way to get people up and running with PowerShell, and a great place to meet other PowerShell enthusiasts.  They’re helpful for PowerShell newcomers, experts, and everything in between.  They’re a wonderful way to learn new things about PowerShell and improve your scripting skills.

The first new Seattle Script club is this Wednesday, September 24th, 2014.   They’ll happen every 4th Wednesday of a month.  The main event will happen in the Civica conference room at the Microsoft offices at 205 108th Ave NE, Bellevue, WA.   Social time will be in Bellevue, at a bar of the group’s choosing.  The first round for newcomers is on Start-Automating.

Here’s what the Seattle Script Club will have in store for you:

PowerShell Presentation (6:00PM-7:30 PM, Civica Conference Room, Microsoft Bellevue Offices (205 108th Ave NE)):

                Each month, we’ll be doing a 1-hour presentation on a topic of interest to Seattle area scripters.  The first month will be on SQL and PowerShell (It’s got some cool scripts in it, don’t miss it!).  The second month will be on PowerShell Cmdlet design.  The third month will be on intranet development with PowerShell.   Each presentation will be followed by extensive Q&A and interesting show and tell by other members of the group.

Socialization (8:00 - ?, Downtown Bellevue):

                After your brains have been thoroughly stuffed with PowerShell knowledge, clear your head and chat with your fellow scripters.  Each month we’ll be hanging out after Script Club and enjoying the company of our fellow scripters.  The first round for new attendees to Script Club is on Start-Automating.

We hope to see many familiar faces at Script Club, and meet new scripters in the Seattle area.

The Seattle Script Club is coordinated by James Brundage from Start-Automating, Craig Martin from Edgile, and Andy Schneider from Avanade

ADAL and PowerShell

ADAL v2 was just released. This is a library that makes it super easy to auth against Azure AD in an application.  Here’s a link to a very quick demo. http://www.cloudidentity.com/blog/2014/09/08/getting-started-with-adal-for-netquick-video-tutorial/

Well, if it can be done in WPF, surely we can do this in PowerShell. The first thing you have to do is make sure you have the Nuget command line tool installed.

Then you just run this command -

nuget install Microsoft.IdentityModel.Clients.ActiveDirectory

 

After that, you can find the 2 dll’s you need in the Microsoft.IdentityModel.Clients.ActiveDirectory.2.9.10826.1824\lib\net45 directory.

Now comes the fun part.

 

Add-Type -Path .\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll 
Add-Type -Path .\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll 
$tenant = "yourdomainhere.onmicrosoft.com" 
$resource = "https://graph.windows.net" 
$clientID = "dfbf167a-add-your-own-clientid-here" 
$redirect = new-object System.Uri("http://powershell") #as long as this is unique in your tenant, all good 
$AuthContext = new-object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext("https://login.windows.net/$tenant") 
$result = $AuthContext.AcquireToken($resource,$clientID,$redirect) 
$result