【发布时间】:2022-01-19 11:52:26
【问题描述】:
我的问题是我在控制台中获得了显示所有机器“名称”、LastLogonDate 描述的列表。但是当我运行完整脚本时,只有 1 台机器信息通过邮件发送。我错过了什么?抱歉,我对 PS 有点陌生。
##Contains my list of computers that I need data from
$Users = 'PCName1', 'PCName2', 'PCName3'
##Gets AdComputer info
$Computers = Get-ADComputer -Filter * -Properties LastLogOnDate, Description
$Users | foreach {
$User = $_
$selectedMachine = $Computers | where Name -eq $User
if ($selectedMachine) {
$selectedMachine | select Name, LastLogOnDate, Description
}
# if it does not exist...
}
[string[]]$recipients = mymail@asds.com
$fromEmail = from@email.com
$server = "IP"
[string]$emailBody = "$Computer" + "Mail Rapport sendt fra task scheduler $computer $time "
send-mailmessage -from $fromEmail -to $recipients -subject "Machines INFO " -body $emailBody -priority High -smtpServer $server
【问题讨论】:
-
欢迎来到 StackOverflow!你好像忘了问一个问题。请update your post 详细说明代码应该做什么、它当前在做什么以及您需要什么帮助。
标签: powershell active-directory