-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkei_lista_dystrybucyjna.ps1
106 lines (66 loc) · 2.09 KB
/
kei_lista_dystrybucyjna.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
<#
.SYNOPSIS
Tworzenie listy dystrybucyjnej na poczcie kai na podstawie danych z msdb
.DESCRIPTION
Niezbede do doinstalowania:
Install-Module -Name SqlServer
.NOTES
autor: hajduk 2019
#>
$sql = "SELECT [IDR]
,[Nazwisko]
,[Imie]
,[Status]
,[Wirtualny]
,[login]
,[Pracuje]
,[EmailSluzbowy]
,[Telefon]
,[WTrakcieWypowiedzenia]
,[WTrakcieWypowiedzeniaData]
FROM [db].[dbo].[Pracownik]
WHERE AktualizujeIDR is NULL
and pracuje = '1'
and (EmailSluzbowy like '%mail1%' or EmailSluzbowy like '%mail2%')
and login not like 'NULL'
and WTrakcieWypowiedzenia = 0
and WTrakcieWypowiedzeniaData is NULL
and (Status = '106' or Status = '107' or Status = '108' )"
$server = "server"
#$database = ""
$username = "user"
$password = "pass"
try {
$AccountToBlock = Invoke-Sqlcmd -Query $sql -ServerInstance $server -QueryTimeout 30 -ErrorAction 'Stop' -username $username -password $password
} catch {
Write-Error "Failure database connection" -EA Stop
}
$maile =@()
$AccountToBlock | % {
if ($_.EmailSluzbowy -ne ""){
$login = $_.EmailSluzbowy
$podzielone = $login.Split("{@}")
$nazwa_konta = $podzielone[0]
$domena = "@mial1.pl"
$mail = $nazwa_konta + $domena
$maile += $mail
}
else{}
}
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", '*/*')
$headers.Add("UserAgent", 'API-CLIENT')
$headers.Add("ContentType", 'application/json')
$headers.Add("KeepAlive", 'true')
$headers.Add("Authorization", 'Basic ????')
$params = @{
'description' ="Lista zaktualizowana przez skrypt: $(Get-Date -format 'u')"
'accounts' = $maile
}
$params = $params | ConvertTo-Json
$url = "https://as23123.e-kei.pl/v1/mailinglists/mail1.pl/lista"
try {
Invoke-RestMethod -Uri $url -Headers $headers -Method 'PUT' -Body $params -ContentType "application/json"
} catch {
Write-Error "Failure kei API connection" -EA Stop
}