-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-ADUserByPhone.ps1
44 lines (32 loc) · 1.17 KB
/
Get-ADUserByPhone.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
<#
.SYNOPSIS
Script to find AD users by phone number
.DESCRIPTION
Script to find AD users by phone number
Enter the pohone number without any other characters e.g.123456789
.EXAMPLE
Get-ADUserByPhone.ps1 -Phone_number 123456789
.EXAMPLE
Get-ADUserByPhone.ps1 123456789
.NOTES
autor: hajdus 2018
#>
Param(
[Parameter(Mandatory = $true)] [String]$Phone_number
)
#Making 3 substrings from entered phone number
$Part1 = $Phone_number.Substring(0, 3)
$Part2 = $Phone_number.Substring(3, 3)
$Part3 = $Phone_number.Substring(6, 3)
$phone0 = $Phone_number
$phone1 = "+48" + $Part1 + $Part2 + $Part3
$phone2 = "+48" + " " + $Part1 + $Part2 + $Part3
$phone3 = "+48" + " " + $Part1 + " " + $Part2 + " " + $Part3
$phone4 = $Part1 + " " + $Part2 + " " + $Part3
$phone5 = $Part1 + "-" + $Part2 + "-" + $Part3
for ($i = 0; $i -le 5; $i++ ) {
$phonetxt = Get-Variable -Name "phone$i" -ValueOnly
echo "Looking for account for number: $phonetxt"
Get-ADUser -Filter * -Properties name, MobilePhone, OfficePhone |
Where-Object {$_.MobilePhone -eq (Get-Variable -Name "phone$i" -ValueOnly) -or $_.OfficePhone -eq (Get-Variable -Name "phone$i" -ValueOnly)}
}