Email the output from power shell script

How can I email the output from the power shell below which runs as a step as part of our deployment?

$threshold = 100000 #Number of days to look for expiring certificates
$deadline = (Get-Date).AddDays($threshold) #Set deadline date
Dir Cert:\LocalMachine\My | foreach {
$_ | Select FriendlyName, Issuer, Subject, NotAfter, @{Label=“Expires In (Days)”;Expression={($_.NotAfter - (Get-Date)).Days}}

Many Thanks

Hi @amushtaq ,

Thanks for getting in touch with us over your question!

You should be able to accomplish this by using output variables and an email step, so the two parts would be as follows.

First, you can store the certificate details from your script into an output variable using a script step. You can find documentation on output variables here:

Once you’ve stored the results into an output variable, then you can use an email step to deliver the contents, referencing the output variable in the previous step. Note that SMTP needs to be configured, and you can find that along with email step documentation here:

Please let us know if this will suit your use case or any further questions we can assist with.



This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.