Powershell SecretStore - Safely Use Credentials or API keys within Script
- Written by: Andrew Wellington
- Category: Powershell
- Hits: 641
When using powershell for scripting, you may need to store credentials within the script. This is insecure especially when dealing with an API key. The preferred way to deal with this is using the powershell SecretStore module. I will go over how to install this module and configure it to allow you to store credentials within a script in an easy and secure way.
Schedule a PowerShell Script with SQL Server Agent
- Written by: Andrew Wellington
- Category: Powershell
- Hits: 479
There are many ways to schedule a PowerShell script to run within windows. The most common way is to use task scheduler however if your PowerShell script is invoking SQL commands, I find it is best to use the SQL server agent to schedule the job. This keeps all of your database based scripts in one place. This is very important when it comes time to upgrade or migrate the server. I will go over how to schedule the script in SQL Server 2016 as well as add email notifications and output to a text file.
Send Email in your PowerShell Script - The Modern Method
- Written by: Andrew Wellington
- Category: Powershell
- Hits: 475
With modern companies using hosted email solutions, Microsoft has deprecated the use of the Send-MailMessage PowerShell cmdlet. The supported to way to send emails from a PowerShell script is with the Microsoft Graph API. Unfortunately, this is not as simple as using an on-premises SMTP server, but it's much more secure. And by building a proper PowerShell function, it's just as easy to integrate within your scripts. This does require an Office365 tenant and subscription. I will outline the steps and give an example of how to send emails with this method.