【发布时间】:2015-11-06 14:15:58
【问题描述】:
我是 Powershell 的新手,我正在尝试通过电子邮件发送输出。如果我在 Powershell 中运行脚本,它会给我正确的输出,但电子邮件只给我 SearchBase OU。
# The 60 is the number of days from today since the last logon
$xDays = (Get-Date).AddDays(-20)
# List of SearchBase locations
$OUs = @('OU1','OU2','OU3','OU4')
$OUs | ForEach-Object {Get-ADComputer -Property Name,CanonicalName,OperatingSystem,LastLogonDate -Filter {LastLogonDate -le $xDays -and Name -NotLike '*-vm'} -SearchBase $_ } | Fl Name,OperatingSystem,CanonicalName,lastLogonDate | Out-String
$From = "x@y.com"
$Rcpnt = "y@y.com"
$SMTP = "smtp.y.com"
$SUBJECT = "Old Computers Report from $env:ComputerName.$env:USERDNSDOMAIN - $((Get-Date).ToShortDateString())"
$Mail_Body = $OUs | Out-String
【问题讨论】:
标签: powershell-4.0