# Before you start do the following:
# 1. Generate encrypted .xml file with O365 credentials to be used for sending emails. Note: if you are sending emails from your own account, use an app password.
# Run following commands:
# $cred = Get-Credential
# $cred | Export-CliXml c:\temp\emailcreds.clixml
# Copy emailcreds.clixml file to location you want and reference its path below as $emailcreds variable. This file is bound to your computer.
$emailcreds = Import-CliXml "C:\Some_Folder\emailcreds.clixml"
$body = & "C:\gam-64\gam.exe" report domain | Select-string -pattern 'accounts:apps_'
$subject = 'G-Suite license report ' + (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
-Port 587 `
-Credential (New-Object System.Management.Automation.PSCredential -ArgumentList $emailcreds) `
-UseSsl `
-Subject $subject `
-Body $body