Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Import and connect
  2. Import-Module C:\Scripts\kvnadm\wsus\PoshWSUS\PoshWSUS.psm1
  3. Connect-PSWSUSServer -WsusServer srv-wsus-01 -Port 8530
  4.  
  5. #Creating function for sending report
  6. function Send-ToAdministrators
  7. {
  8.     param (
  9.     [Parameter (Mandatory = $false)][string] $SmtpServer = "mail.brrb.by",
  10.     [Parameter (Mandatory = $false)][string] $To = "kozyarskij.v@brrb.by",
  11.     [Parameter (Mandatory = $false)][string] $From = "service-wsus@brrb.by",
  12.     [Parameter (Mandatory = $false)][string] $Subject = "TestMessage",
  13.     [Parameter (Mandatory = $false)][string] $Attachments = "",
  14.     [Parameter (Mandatory = $false)][string] $Body = "c:\1.txt"
  15.     )
  16.     Send-MailMessage -SmtpServer $SmtpServer -To $To -From $From -Subject $Subject -Attachments $Attachments -Body $Body
  17. }
  18. #X. Creating function of settings date's period
  19. function Get-WeekAgo
  20. {
  21.     (Get-Date -Date (Get-Date).AddDays($args[0])).ToString("yyyy.MM.dd")
  22. }
  23.  
  24. #Set environments
  25. $props=@{}
  26. $report1=@()
  27. $GetLists = Get-PSWSUSUpdate | where {$_.ArrivalDate.ToString("yyyy.MM.dd") -ge (Get-WeekAgo -14) -and $_.ArrivalDate.ToString("yyyy.MM.dd") -le (Get-WeekAgo -7) -and $_.ProductTitles -match 'Windows 10' -and $_.UpdateClassificationTitle -eq 'Security Updates'}
  28.  
  29. Foreach ($GetList in $GetLists){
  30.     $props = [ordered]@{
  31.     NumberUpdate=$GetList.KnowledgebaseArticles
  32.     Product=$GetList.ProductTitles
  33.     Title=$GetList.Title
  34.     ArDate=$GetList.ArrivalDate
  35.     }
  36. $obj = New-Object -TypeName PSObject -Property $props
  37. $report1 += $obj
  38. }
  39.  
  40. $report1 | Format-Table -AutoSize > C:\Temp\1.txt
  41. $body1 = Get-Content -Path C:\TEMP\1.txt | Out-String
  42. #$report1 | Export-Csv -Path C:\Temp\result.csv -NoTypeInformation -Delimiter ";" -Encoding Default
  43. Send-MailMessage -SmtpServer "mail.brrb.by" -To "kozyarskij.v@brrb.by" -From "service-wsus@brrb.by" -Subject "TestMessage" -Attachments "C:\TEMP\1.txt" -Body $body1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement