-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-ADUserAzure.ps1
42 lines (38 loc) · 1.17 KB
/
Get-ADUserAzure.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
function Get-ADUserAzure {
<#
.SYNOPSIS
Gets the AzureAD account from the sAMAccountname of on-premises user
.DESCRIPTION
Looks up the on-premises sAMAccountname and queries AzureAD using the UPN from the on-premises account.
.PARAMETER username
sAMAccountname of on-premises user account
.EXAMPLE
Get-ADUserAzure brett.miller
.NOTES
Saves having to type out the full UPN of a user to look them up in AzureAD
#>
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true,
Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[ValidateScript({
try {
(Get-aduser -identity $_ -ErrorAction Stop)
$true
}
catch {
throw "User does not exist"
}
})]
[string[]]$username
)
process {
foreach ($user in $username) {
get-azureaduser -objectid (get-aduser -Identity $user).userprincipalname
}
}
}