Планировщик заданий разборки ConvertTo-Html - PullRequest
0 голосов
/ 21 января 2019

У меня есть скрипт, который генерирует некоторую информацию из Citrix (машины, которые не зарегистрированы, в мм и т. Д.).Если я запускаю это в PowerShell ISE, HTML проходит нормально.Если я запускаю его как запланированное задание, используя те же кредиты, то оно получается в виде простого текста.И в теле письма, и во вложении. Задача задается как powershell.exe, а аргументами является путь.Он запускается независимо от того, вошел ли пользователь в систему и имеет ли он самые высокие привилегии.

$head = @"
<style>
body { background-color:#E5E4E2;
       font-family:Monospace;
       font-size:10pt; }
td, th { border:0px solid black; 
         border-collapse:collapse;
         white-space:pre; }
th { color:white;
     background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px ;white-space:pre; }
tr:nth-child(odd) {background-color: lightgray}
table { width:95%;margin-left:5px; margin-bottom:20px;}
h2 {
 font-family:Tahoma;
 color:#6D7B8D;
}
.footer 
{ color:green; 
  margin-left:10px; 
  font-family:Tahoma;
  font-size:8pt;
  font-style:italic;
}
</style>
"@

$bd = Get-BrokerDesktop -MaxRecordCount 5000
$unregisteredonlineVMs = $bd |
    ? {
        ($_.RegistrationState -eq 'Unregistered') -and
        ($_.PowerState -eq 'On')
    } |
    select HostedMachineName,DesktopGroupName,LastDeregistrationReason |
    ConvertTo-Html -Property HostedMachineName, DesktopGroupName, LastDeregistrationReason -Head $head 
$unregisteredofflineVMs = $bd |
    ? {
        ($_.RegistrationState -eq 'Unregistered') -and
        ($_.PowerState -eq 'Off')
    } |
    select HostedMachineName,DesktopGroupName,LastDeregistrationReason |
    ConvertTo-Html -Property HostedMachineName, DesktopGroupName, LastDeregistrationReason -Head $head 
$unknownVMs = $bd |
    ? {
        ($_.RegistrationState -eq 'Unregistered') -and
        ($_.PowerState -eq 'Unknown')
    } |
    select DNSName,DesktopGroupName,LastDeregistrationReason |
    ConvertTo-Html -Property DNSName, DesktopGroupName, LastDeregistrationReason -Head $head 
$mmVMs = $bd |
    ? { $_.InMaintenanceMode -eq 'True' } |
    select HostedMachineName,DesktopGroupName,LastDeregistrationReason |
    ConvertTo-Html -Property HostedMachineName, DesktopGroupName, LastDeregistrationReason -Head $head

$body = "<h1><b>Unregistered Online</b></h1> $unregisteredonlineVMs" + "`n`n" + "<h1><b>Unregistered Offline</b></h1> `n`n $unregisteredofflineVMs" + "`n`n" + "<h1><b>Unregistered Unknown Powerstate</b></h1> `n`n $unknownVMs" + "`n`n" +  "<h1><b>Maintenance Mode</b></h1> `n`n $mmVMs" 
$attach = "<h1><b>Unregistered Online</b></h1> $unregisteredonlineVMs" + "`n`n" + "<h1><b>Unregistered Offline</b></h1> `n`n $unregisteredofflineVMs" + "`n`n" + "<h1><b>Unregistered Unknown Powerstate</b></h1> `n`n $unknownVMs" + "`n`n" +  "<h1><b>Maintenance Mode</b></h1> `n`n $mmVMs" | Out-File C:\Temp\VirtualDesktopCheck\XenDestkopCheck_$time.html

Send-MailMessage -From $fromEmail -To $recipients -Subject "XenDesktop Daily Check $time" -Body $body -Priority High -SmtpServer $server -BodyAsHtml -Attachments C:\Temp\VirtualDesktopCheck\XenDestkopCheck_$time.html
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...