As an example, let's assume that Dave Smith is going on an extended vacation. Dave's manager, Harry, needs to receive all of his e-mails.
First, we'll write a PowerShell script that will configure Microsoft Exchange to forward Dave's e-mails to HarryR@MVPSI.COM:
[System.Management.Automation.PSCredential]$Credential = Get-JAMSCredential DanielS@MVPSI.com
$PSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Credential -Authentication Basic -AllowRedirection
Import-PSSession $PSSession
Set-Mailbox "Dave Smith" -ForwardingAddress HarryR@MVPSI.com
Remove-PSSession $PSSession
Let's review the steps in our script:
Line 1: We use JAMS secure stored credentials to retrieve the login information for our Administrator, Daniel.
Line 2: We establish a connection with the relevant Microsoft Exchange server where the changes will be made.
Line 3: We import the PowerShell session for usage.
Line 4: The action is taken on Dave Smith's mailbox to ensure that messages sent to Dave are forwarded to Harry.
Line 5: This line ends the PSSession created on line 2.
Our script works, but it isn't robust. As more forwarding requests come in from managers, we realize that manually editing the script is taking up too much of the day.
It's time to flex some JAMS muscle - by creating flexible scripts using JAMS Parameters.
Creating Flexible Scripts Using JAMS Parameters
Continuing our example above, we know we need to forward mail from an employee on vacation to that employee's manager. Now, where our PowerShell script above used hard-coded values for employee name and the forwarding address, we'll replace them with JAMS parameters we can set at runtime. Let's see what our script would look like with parameters:
[System.Management.Automation.PSCredential]$Credential = Get-JAMSCredential DanielS@MVPSI.com $PSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Credential -Authentication Basic -AllowRedirection Import-PSSession $PSSession Set-Mailbox "<<VacationUserName>>" -ForwardingAddress "<<VacationUserManager>>" Remove-PSSession $Session
Above, we've added a VacationUserName and VacationUserManager parameter that we can set when we submit the script to run. Let's see what setting those values at runtime would look like:
With parameters in our script, we now have a self-service JAMS Job that can be configured at runtime to reflect the necessary users involved in the exchange forwarding.
By using JAMS to run our script as a JAMS Job, we can configure the Job to run at a later date or time, use native version control to roll back to previous versions of our script, and even configure security to allow managers to submit their own forwarding request- removing our need to manually run a script whenever an employee goes on vacation!
Comments