-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathm365-lab.ps1
43 lines (34 loc) · 1.29 KB
/
m365-lab.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
import-module azuread
# azure ad
Connect-AzureAD
# count all user accounts
Get-Command -Module azuread -noun azureaduser
Get-AzureADUser -All $true | Measure-Object
$all = Get-AzureADUser -All $true
$all | Get-Member
$all.city
# sort / group department
Get-AzureADUser -All $true | Select-Object department -Unique
$all.department | Select-Object -Unique
$all | Group-Object department
# user without department
$all | Group-Object department | select -ExpandProperty Group -First 1
$all | sort department | ft -AutoSize department,displayname
$all | Where-Object{$PSItem.department -notlike ""}
$all | Where-Object{$PSItem.department -ne $null -and $_.country -like "Unit*"}
# Filter parameter
Get-AzureADUser -Filter "country eq 'United States'"
Get-AzureADUser -Filter "startswith(country,'unit')"
$alias = $all.userprincipalname -replace ("@M365x682019.OnMicrosoft.com","")
SMTP:vorname.nachname@contoso.com
$all | ForEach-Object{
$pre = "SMTP:" + $_.displayname -replace (" ",".")
$pre + "@" +(Get-AzureADDomain).Name
}
# Solution with foreach loop
$domain = "contoso.com"
foreach ($user in $allUsers) {
$displayName = $user.DisplayName.Split(" ").ToLower()
$upn = $user.UserPrincipalName.Split("@").ToLower()
Write-Host "SMTP:$($displayName[0]).$($displayName[1])@$($domain)"
}