Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Import and connect
- Import-Module C:\Scripts\kvnadm\wsus\PoshWSUS\PoshWSUS.psm1
- Connect-PSWSUSServer -WsusServer srv-wsus-01 -Port 8530
- #Creating function for sending report
- function Send-ToAdministrators
- {
- param (
- [Parameter (Mandatory = $false)][string] $SmtpServer = "mail.brrb.by",
- [Parameter (Mandatory = $false)][string] $To = "kozyarskij.v@brrb.by",
- [Parameter (Mandatory = $false)][string] $From = "service-wsus@brrb.by",
- [Parameter (Mandatory = $false)][string] $Subject = "TestMessage",
- [Parameter (Mandatory = $false)][string] $Attachments = "",
- [Parameter (Mandatory = $false)][string] $Body = "c:\1.txt"
- )
- Send-MailMessage -SmtpServer $SmtpServer -To $To -From $From -Subject $Subject -Attachments $Attachments -Body $Body
- }
- #X. Creating function of settings date's period
- function Get-WeekAgo
- {
- (Get-Date -Date (Get-Date).AddDays($args[0])).ToString("yyyy.MM.dd")
- }
- #Set environments
- $props=@{}
- $report1=@()
- $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'}
- Foreach ($GetList in $GetLists){
- $props = [ordered]@{
- NumberUpdate=$GetList.KnowledgebaseArticles
- Product=$GetList.ProductTitles
- Title=$GetList.Title
- ArDate=$GetList.ArrivalDate
- }
- $obj = New-Object -TypeName PSObject -Property $props
- $report1 += $obj
- }
- $report1 | Format-Table -AutoSize > C:\Temp\1.txt
- $body1 = Get-Content -Path C:\TEMP\1.txt | Out-String
- #$report1 | Export-Csv -Path C:\Temp\result.csv -NoTypeInformation -Delimiter ";" -Encoding Default
- 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