-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathConnect-AzureAD-Scripts.ps1
36 lines (23 loc) · 1.17 KB
/
Connect-AzureAD-Scripts.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
# Install-Module -Name Msonline
# Install-Module -Name AzureADPreview -AllowClobber
# Connect to AzureAD
$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential
Connect-AzureAD -Credential $UserCredential
$UPN = "tony@sample.com"
# Get All Logs
Get-AzureADAuditSignInLogs -Filter "userPrincipalName eq '$UPN'"
# Save Logs to JSON File
$Logs = Get-AzureADAuditSignInLogs -Filter "userPrincipalName eq '$UPN'"
foreach ($log in $Logs){
$log | ConvertTo-Json -Compress | Out-File AzureADAuditSignInLogs.json -Append
}
# Get Last Login
Get-AzureAdAuditSigninLogs -top 1 -filter "userprincipalname eq '$UPN'" | select CreatedDateTime
# Create a lookup table for ResourceAppId GUID's
Get-AzureADServicePrincipal -All:$True | Select-Object AppId, Displayname | Sort-Object DisplayName | export-csv -NoTypeInformation principal-appid.csv
# Sign out a user from all active sessions and disable account after a max of 1h or when app/browser is closed, whichever comes first.
$User = Get-AzureADUser -Filter "UserPrincipalName eq 'user@contoso.com'"
$User | Revoke-AzureADUserAllRefreshToken
$User | Disable-ADAccount
$User | Set-AzureADUser -AccountEnabled $false