Created
May 13, 2019 15:44
-
-
Save ArtisanByteCrafter/cb2b3076f7bf9e566bda961de54a781f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Orgs = @('Default', 'YourOrg1', 'YourOrg2') | |
$Result = Foreach ($Org in $Orgs) { | |
$params = @{ | |
Server = "https://kace.example.com" | |
Org = $Org | |
Credential = (Get-Credential) # or supply stored creds in desired manner | |
QueryParameters = "?paging=limit all" | |
} | |
$query = Get-SmaMachineInventory @params | |
[PSCustomObject]@{ | |
"Org" = $Org | |
"Inventory Count" = $query.Count | |
} | |
} | |
$HtmlParams = @{ | |
PreContent = "<H2>$ReportTitle </H2> | |
<span>$PreText</span> | |
<br></br> | |
" | |
head = @" | |
<Title>$ReportTitle</Title> | |
<style> | |
table { | |
font-family: arial, sans-serif; | |
border-collapse: collapse; | |
width: 100%; | |
} | |
td { | |
border: 1px solid #dddddd; | |
text-align: left; | |
padding: 8px; | |
} | |
th { | |
border: 1px solid #dddddd; | |
text-align: left; | |
color: white; | |
background-color: #a80000; | |
padding: 8px; | |
} | |
tr { | |
border: 1px solid #dddddd; | |
text-align: left; | |
padding: 8px; | |
background-color: #FFFFFF; | |
color: #222222; | |
} | |
tr:nth-child(even) { | |
background-color: #bebebe; | |
color: #222222; | |
} | |
.footer { | |
color:black; | |
padding: 8px; | |
margin-left:10px; | |
font-family:Tahoma; | |
font-size:12pt; | |
background-color: #BFE8A5; | |
} | |
</style> | |
"@ # do not indent - here-string closings must be at start-of-line. | |
PostContent = " | |
<br></br> | |
<span>Generated on: $(get-date)</span> | |
" | |
} | |
$EmailBody = $Result | ConvertTo-Html @HtmlParams | Out-String | |
$mailparams = @{ | |
From = 'from@example.com' | |
To = 'to@example.com' | |
Subject = 'Org Machine Report' | |
Body = $EmailBody | |
BodyAsHTML = $true | |
smtpServer = 'smtp.example.com' | |
port = 25 | |
} | |
Send-MailMessage @mailparams |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment