-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateSerach.ps1
executable file
·119 lines (91 loc) · 5.16 KB
/
updateSerach.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
## This scipt installs new Windows Defender signatures and search for new Windows updates
## It send an e-mail when the work is done
### load settings.txt
Get-Content "C:\Users\Administrator\Documents\Skripte\settings.txt" | foreach-object -begin {$h=@{}} -process { $k = [regex]::split($_,'='); if(($k[0].CompareTo("") -ne 0) -and ($k[0].StartsWith("[") -ne $True)) { $h.Add($k[0], $k[1]) } }
# to get an item $h.Get_Item("MySetting1")
### Windows Defender
$Versions = Get-MpComputerStatus
$oldVersion = $Versions | select -ExpandProperty AntispywareSignatureVersion
Update-MpSignature
$Versions = Get-MpComputerStatus
$newVersion = $Versions | select -ExpandProperty AntispywareSignatureVersion
$newDate = $Versions | select -ExpandProperty AntispywareSignatureLastUpdated
$fScan = $Versions | select -ExpandProperty FullScanStartTime
$qScan = $Versions | select -ExpandProperty QuickScanStartTime
$mailBody = ""
### Windows update
$Computername = $env:COMPUTERNAME
$updatesession = [activator]::CreateInstance([type]::GetTypeFromProgID("Microsoft.Update.Session",$Computername))
$UpdateSearcher = $updatesession.CreateUpdateSearcher()
$searchresult = $updatesearcher.Search("IsInstalled=0")
$count = $searchresult.Updates.Count
if ( $count -gt 0) {
# create Mail Body
$mailBody = $mailBody + "################################### Windows Update #######################################`n"
$mailBody = "There are " + $count + " new update(s) for " + $Computername + " available:`n`n"
For ($i=0; $i -lt $Count; $i++) {
$Update = $searchresult.Updates.Item($i)
$mailBody = $mailBody + "Title: " + $Update.Title + "`n"
$mailBody = $mailBody + "KB: " + $Update.KBArticleIDs + "`n"
$mailBody = $mailBody + "Security bulletin IDs: " + $Update.SecurityBulletinIDs + "`n"
$mailBody = $mailBody + "Msrc severity: " + $Update.MsrcSeverity + "`n"
$mailBody = $mailBody + "Is downloaded: " +$Update.IsDownloaded + "`n"
$mailBody = $mailBody + "Info url: " + $Update.MoreInfoUrls + "`n`n"
}
} else {
$mailBody = $mailBody + "################################### Windows Update #######################################`n"
$mailBody = $mailBody + "No updates available.`n`n"
}
if( $oldVersion -ne $newVersion ){
$mailBody = $mailBody + "`n################################### Windows Defender #####################################`n"
$mailBody = $mailBody + "New signature from " + $newDate + " installed.`n"
$mailBody = $mailBody + "New verion: " + $newVersion + "`n"
$mailBody = $mailBody + "Old verion: " + $oldVersion + "`n"
$mailBody = $mailBody + "Last quick scan: " + $qScan + "`n"
$mailBody = $mailBody + "Last full scan: "+ $fScan + "`n`n"
} else {
$mailBody = $mailBody + "`n################################### Windows Defender #####################################`n"
$mailBody = $mailBody + "No updates available.`n"
$mailBody = $mailBody + "Current signature( "+ $newVersion + ") - " + $newDate + " `n"
$mailBody = $mailBody + "Last quick scan: " + $qScan + "`n"
$mailBody = $mailBody + "Last full scan: "+ $fScan + "`n`n"
}
#
# Send Mail
if ( ( $oldVersion -ne $newVersion ) -or ( $count -gt 0 ) ) {
# to force TLS11 or higher
[System.Net.ServicePointManager]::SecurityProtocol = 'TLS11,TLS12'
$PSEmailServer = $h.Get_Item("mailSmtpURL")
$pw = Get-Content $h.Get_Item("mailPw") | ConvertTo-SecureString
$to = $h.Get_Item("mailTo")
$from = $h.Get_Item("mailFrom")
$cc = $h.Get_Item("mailCC")
$cred = New-Object System.Management.Automation.PSCredential $from, $pw
if ( $oldVersion -ne $newVersion ) {
$mailSubject = "New security signature installed on " + $Computername + ""
} else {
$mailSubject = "Updates on " + $Computername + " available!"
}
if ( !$cc ) {
Send-MailMessage -Credential $cred -from $from -to $to -Subject $mailSubject -body $mailBody -encoding ([System.Text.Encoding]::UTF8) -UseSSL
} else {
Send-MailMessage -Credential $cred -from $from -to $to -CC $cc -Subject $mailSubject -body $mailBody -encoding ([System.Text.Encoding]::UTF8) -UseSSL
}
} else {
if ( $h.Get_Item("SendMailAlway") -eq "True" ) {
# to force TLS11 or higher
[System.Net.ServicePointManager]::SecurityProtocol = 'TLS11,TLS12'
$PSEmailServer = $h.Get_Item("mailSmtpURL")
$pw = Get-Content $h.Get_Item("mailPw") | ConvertTo-SecureString
$to = $h.Get_Item("mailTo")
$from = $h.Get_Item("mailFrom")
$cc = $h.Get_Item("mailCC")
$cred = New-Object System.Management.Automation.PSCredential $from, $pw
$mailSubject = "No Updates on " + $Computername + " available"
if ( !$cc ) {
Send-MailMessage -Credential $cred -from $from -to $to -Subject $mailSubject -body $mailBody -encoding ([System.Text.Encoding]::UTF8) -UseSSL
} else {
Send-MailMessage -Credential $cred -from $from -to $to -CC $cc -Subject $mailSubject -body $mailBody -encoding ([System.Text.Encoding]::UTF8) -UseSSL
}
}
}