Reports erzeugen mit Powershell

Heute bekam ich von einer Leserin meines Blogs folgendes Powershell Skript zugesandt, das alle Bilder größer 1MB sucht in in einer HTML Datei auflistet, die dann verschickt wird.

Vielen Dank an Andrea!

"
$a = $a + "BODY{background-color:#ffffff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:grey}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#ffffff}"
$a = $a + ""

gci "C:\Users\Uwe\" -recurse -include *.jpg,*.bmp,*.png | Where-Object {$_.Length -gt 1000KB} |
? { $_.PSisContainer -eq $false} |
Sort-Object length -descending | Select-Object Name, @{Name="Kbytes";Expression={ "{0:N0}" -f ($_.Length / 1Kb) }}, DirectoryName, CreationTime | ConvertTo-HTML -head $a -body "

Grosse Bilder

" | out-file "C:\report.htm" #Send Email $msg = $null $smtpServer = "0.0.0.0" $workpath = “\\Server\Share\Verzeichnis” $file = “$workpath\report.htm” $msg = new-object Net.Mail.MailMessage $att = new-object Net.Mail.Attachment($file) $smtp = new-object Net.Mail.SmtpClient($smtpServer) $msg.From = "sender@domain.com" $msg.To.Add("empfaenger@domain.com") #$msg.To.Add("empfaenger2@domain.com") $msg.Subject = "Bilder Report" $msg.IsBodyHTML = $true $html = "Report der Bilder" $msg.Body = $html $msg.Attachments.Add($att) $smtp.Send($msg)

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website