目标:搜索所有在 ipPhone 属性中有内容的禁用用户,将结果通过电子邮件发送到电子邮件地址。
问题:当我收到电子邮件时,数据未按用户帐户或表格分隔不知道如何更正
代码:
#Add-WindowsFeature RSAT-AD-PowerShell
#needed for server 2012+ if no rstat tools installed on it
#Import-Module activedirectory
#Need to import modeule to read powershell
$emailto = 'markbuehler@milgard.com'
$emailfrom = 'markbuehler@milgard.com'
$emailsubject = "Disabled Users who have IpPhone Attribute Active"
$smtp_server = 'corp-smtp01.milgardwindows.com'
$disabledusers = get-aduser -SearchBase
"OU=MIMilgardUsersandComputers,DC=milgardwindows,DC=com" -Filter {(Enabled -eq $false -and
ipPhone -like "*")} -Properties * | Select-Object Name,UserPrincipalName,Office,ipPhone |
Format-Table -Property Name,UserPrincipalName,Office,ipPhone
Send-MailMessage -To $emailto -From $emailfrom -Subject $emailsubject -SmtpServer $smtp_server
-BodyasHtml ($disabledusers | Out-String)'
电子邮件正文结果:
Name UserPrincipalName Office ipPhone ---- ----------------- ------ ------- Adi Rasilau
AdiRasilau@milgard.com Milgard - Sacramento 2742 Nai Jones NaiJones@milgard.com Milgard -
Sacramento 2780 Phillip Wheeler PhillipWheeler@milgard.com Milgard - Sacramento 2727 Joy
Rogers JoyRogers@milgard.com Milgard - Temecula 3286"