PowerShell 定时输出citrix desktop昨日连接会话

asnp citrix*
$now_date = [datetime]::Today
$day2 = [datetime]::Today - [TimeSpan]::FromHours(24)
$fiel_name_date = $now_date.ToString('yyyy-MM-dd')
$all_conn_sessions = Get-BrokerConnectionLog -MaxRecordCount 100000 -Filter {EstablishmentTime -lt $now_date } | Sort-Object BrokeringUserName -Unique | Select-Object BrokeringUserName,EstablishmentTime,MachineName
$list_array = @()
foreach ($all_conn_session in $all_conn_sessions)
{
  if ($all_conn_session.EstablishmentTime -gt $day2)
  {
    $list_array += $all_conn_session

  }
}
$b ="成功会话总数:" + $list_array.Count
$a = $list_array | Out-String

## 日志输出
$b >> C:\citrix_connect_log\$fiel_name_date.csv
$a >> C:\citrix_connect_log\$fiel_name_date.csv

 

##邮件输出
$smtpServer = "xxx.xxx.xx.xxx"
$smtpUser = "xx@xxx.xxx"
$smtpPassword = "xxxxxxxxx"
$mail = New-Object System.Net.Mail.MailMessage
$MailAddress="xxxxx@xxxx.xxx"
$MailtoAddress="xxxxx@xxx.xxx"
$mail.From = New-Object System.Net.Mail.MailAddress($MailAddress)
$mail.To.Add($MailtoAddress)
$mail.Subject = "Citrix 桌面会话总量"+ "--" + $now_date;
$mail.Priority = "High"
$mail.Body = $b + $a
$smtp = New-Object System.Net.Mail.SmtpClient -argumentList $smtpServer
$smtp.Credentials = New-Object System.Net.NetworkCredential -argumentList $smtpUser,$smtpPassword
$smtp.Send($mail)

posted @ 2020-10-20 15:02  小木目心  阅读(214)  评论(0编辑  收藏  举报