A Power Shell Script can be scheduled using the Windows Task Scheduler. Once you have the PowerShell script ready, you could schedule the PowerShell script by launching the Windows Task Scheduler
- On the right click on Create Basic Task
- Then it would open up a small window which has three main tabs that you need to focus on-General, Triggers and Actions.
- On the General tab, select the radio button “Run whether a user is logged in or not”or otherwise depending on whether you want to run the script when the user is logged In.
- On the Triggers tab, specify the time/frequency when the script needs to run.
- On the Actions Tab, Choose the Action “Start a Program” from the Dropdown and enter PowerShell.exe. Then against the parameters specify the Path of the PowerShell script and click OK.
Now your PowerShell script would run at the scheduled time provided the system is powered ON.
Sending an email via PowerShell is pretty easy! All you need to know apart from the sender’s email address is the SMTP Server.
Here is a basic template of sending an email via Power Shell
$From = "YourEmail@domain.com"
$To = "Sender@Domain.com"
$Cc = "CC@YDomain.com"
$Subject = "Email Subject"
$Body = "Insert body text here"
$SMTPServer = "smtp.domain.com"
$SMTPPort = "587"
Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject `
-Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
Just like in Visual Studio, it is helpful to know the matching brace in the Power Shell Editor. If you are near the opening brace, it would tell you where the closing brace is and vice-versa.
Power Shell ISE is the Power Shell Editor for Windows. In order to find the matching brace, one would have to type the following keyboard shortcut
There maybe times when you need to find the date of the year that could be used in your script. There are 365 days in a year, 366 when it is a leap year. Power Shell has a single statement that helps one find out the date of the year.
Get-Date -UFormat %j
Each language has it’s own way for adding comments. Power Shell uses Hash Tags for commenting purposes.
One can add comments to these statements in this way-
Power Shell is a scripting tool from Microsoft. One can write scripts to automate processes or tasks in Windows. The boundaries of Power Shell is not confined to only Windows, Power Shell is being used in other Microsoft Technologies like SharePoint, Exchange and Office 365.
Power Shell scripts are saved with the extension ps1 . It is written in an ISE called Windows PowerShell ISE. This is where you can write scripts and test it.
There is not a straight forward process to forward email from a distribution list to an Office 365 Group. You would need to follow these steps in order to do that-
- Create a Shared Mailbox.
- Add the newly created Shared Mailbox as a member of the distribution list. Doing so would allow the Shared Mailbox to receive email from the distribution list.
- Set up Email forwarding in the shared mailbox to forward email to the Office 365 Group. Now there is a point to be noted here, you would not be able to do this in the Exchange Online Admin Center. You would need to use Power Shell in Order to setup forwarding to an Office 365 Group.