This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ListContacts.ps1
57 lines (50 loc) · 2.68 KB
/
ListContacts.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
############################################################################################################################
# OFFICE 365: Search and show contacts & aliases (starting from a mail domain)
#----------------------------------------------------------------------------------------------------------------
# Autore: GSolone
# Versione: 0.2
# Utilizzo: .\ListContactsAlias.ps1
# Info: https://gioxx.org/tag/o365-powershell
# Ultima modifica: 11-09-2015
# Modifiche:
# 0.2- ho incluso nella ricerca anche gli alias delle caselle di posta di Exchange, così da riuscire ad individuare possibili altri indirizzi presenti in Exchange ma non dichiarati come contatti (valgono sia gli alias, sia i Primary SMTP Address).
############################################################################################################################
#Main
Function Main {
""
Write-Host " Office 365: Search and show contacts & aliases" -f "green"
Write-Host " --------------------------------------------------"
Write-Host " ATTENZIONE:" -f "red"
Write-Host " Fare molta attenzione ai possibili errori di digitazione" -f "red"
Write-Host " nei dati richiesti qui di seguito" -f "red"
""
Write-Host "-------------------------------------------------------------------------------------------------"
$RicercaDominio = Read-Host "Dominio da analizzare (esempio: contoso.com) "
try {
Write-Progress -Activity "Download dati da Exchange" -Status "Ricerco i contatti con il dominio richiesto..."
$RicercaContatti= Get-Contact -ResultSize Unlimited | where {$_.WindowsEmailAddress -like "*@" + $RicercaDominio}
""
Write-Host "Risultato della ricerca:" -f green
$RicercaContatti | ft DisplayName, WindowsEmailAddress
""
# Ricerca degli alias (solo su richiesta)
$title = ""
$message = "Vuoi che estenda la ricerca anche negli alias di posta? (default: NO)"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Verifica adesso."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Non ora."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 1)
if ($result -eq 0) {
""; Write-Progress -Activity "Download dati da Exchange" -Status "Ricerco gli alias di posta con il dominio richiesto...";
$RicercaMailbox= Get-Mailbox -ResultSize Unlimited | where {$_.EmailAddresses -like "*@" + $RicercaDominio}
$RicercaMailbox | ft DisplayName, WindowsEmailAddress
}
""
} catch {
Write-Host "Errore nell'operazione, riprovare." -f "red"
write-host $error[0]
return ""
}
}
# Start script
. Main