PowerShell如何计算邮件中html表中的所有行

时间:2016-01-13 09:33:52

标签: html css powershell

此PowerShell代码正在创建一个html表,并向表中显示的所有用户发送邮件,但是如何添加计数器。所以我可以看到总行数。

这是我的代码:

$CurrentDate = Get-Date
$SubjectDate = $CurrentDate.ToString('yyyy-MM-dd')
$EmailFrom = "test@test.com"
$EmailTo = "test@test.com"
$EmailSubject = "Test mail " + $SubjectDate
$SMTP = "smtp.mail.com"
$Head = Get-Content "C:\path\css.txt"
$Footer = "<br><br> This report is a test <br> Generated on $CurrentDate "
$Body = Get-ADUser -Filter * -SearchBase "OU=Users,OU=SOME,OU=DOMAIN" -Properties * | Where { $_.enabled -ne $false } | Select Name | ConvertTo-Html -Head $Head -PostContent $Footer -As Table | Out-String
Send-MailMessage -to $EmailFrom -from $EmailTo -subject $EmailSubject -Body $Body -BodyAsHtml -SmtpServer $EmailServer

1 个答案:

答案 0 :(得分:0)

您可以添加用户计数,如下所示:

$Users = Get-ADUser -Filter * -SearchBase "OU=Users,OU=SOME,OU=DOMAIN" -Properties * | Where { $_.enabled -ne $false }
$Body =  $Users | Select Name | ConvertTo-Html -Head $Head -PostContent $Footer -As Table | Out-String
Write-Host "Total Users: $($Users.Count)"
Send-MailMessage -to $EmailFrom -from $EmailTo -subject $EmailSubject -Body $Body -BodyAsHtml -SmtpServer $EmailServer