I company I work for just completed an O365 tenant migration. After email had been moved to a new Exchange tenant, we noticed that users continued to use their Outlook apps on their phones. They were also continuing to chat on the old tenant's Teams and were using all of the Office apps on the web using their cached logins.
This caused a headache. Some users were in the new environment with the correct domain—others didn't notice the “@onmicrosoft.com” and were having issues with SSO apps that had been migrated.
We needed to revoke all of the cached login tokens force log out all users. This quick Powershell command did the trick:
Import-Module -Name "AzureAD"
Connect-AzureAD
# Get all users
$users = Get-AzureAdUser -All $true
# Revoke all refresh tokens for each user
$users | ForEach-Object {
Revoke-AzureADUserAllRefreshToken -objectID $_.objectID
}
UPDATE: August 16, 2024: The Azure AD PowerShell module is retired, so you will need to use the MS Graph module instead:
Import-Module -Name 'Microsoft.Graph.Users.Actions'
Connect-MgGraph -Scopes 'User.RevokeSessions.All'
# Get all users
$users = Get-MgUser -All
# Revoke all refresh tokens for each user
$users | ForEach-Object {
Revoke-MgUserSignInSession -UserId $_.Id
}
After this runs, all users will be required to log in again. This forced them to go into the new tenant and solved our SSO issues.
Here's a script that I'm using to roll out the Quest ODM agent on PCs in my environment that do not have access to the LAN. I used Atera Service Desk to deploy it for internet-only installation.
Once that's complete, you will need to upload the file to a publicly accessible file share. I used Azure Files to create a storage container and provide direct access to the file. This URI will be pointed to in the script, so you cannot use something like OneDrive or SharePoint without special configuration.
Script
Before running this script, you will need to change the following XXX values:
$QuestODMMSIURI – This will be the publicly accessible MSI that you uploaded to your file share.
I wrote up a quick and dirty Powershell script today that adds a split-tunnel VPN connection, asks the user for connection info, dials the connection, then configures static routes.
# Add-MerakiVPN.ps1
# Creates a split-tunnel VPN connection and adds static routes.
# Tim D'Annecy 2021-09-08
function Add-MerakiVPN {
$ServerAddress = 'blahblahblah.dynamic-m.com' # Change this value to match your Meraki hostname
$ConnectionName = 'Meraki VPN'
$PresharedKey = 'blah' # Change this value
Add-VpnConnection `
-Name $ConnectionName `
-ServerAddress $ServerAddress `
-TunnelType L2tp `
-EncryptionLevel Optional `
-SplitTunneling `
-AllUserConnection `
-L2tpPsk $PresharedKey `
-AuthenticationMethod Pap, MSChapv2 `
-Force
$StaticRoutes = @(
'10.0.13.0/24', # Change these to match your internal subnets
'10.0.12.0/24',
'172.16.0.0/16'
)
try {
rasphone.exe -d $ConnectionName
Start-Sleep -Seconds 30
$StaticRoutes | foreach {
New-NetRoute -DestinationPrefix $_ -InterfaceAlias $ConnectionName
}
}
catch {
Write-Error 'There was an error adding the VPN connection'
exit
}
}
Add-MerakiVPN
This one-liner imports a CSV formatted with at least the header Name and a list of user names. It outputs to a CSV with the SamAccountName and Enabled properties.
I found this post on Reddit and wanted to save the command for my notes.
Running this command in Powershell will give you the PC's currently connected SSID. This is handy for troubleshooting network issues when connected remotely through a PSSession.
If you're using Microsoft Exchange Online, there's no way to currently see when a Mail Contact was created on the web dashboard.
I wanted to know when an address was added as a Mail Contact in one of our tenants, but I also wasn't able to get an audit trail using the Microsoft Compliance center.
As a workaround, this Powershell command will give the basic info for “WhenCreated”.
While most organizations are moving files to cloud-based solutions, I'm working for a client who wants to keep everything in-house. In this environment, some users had a private folder under a previous drive letter mapping, others didn't have anything at all.
I created this quick and dirty Powershell script to automate the cleanup process for existing users.
This script gets all users from AD, sets their HomeDirectory attribute in AD to a fileshare and mounts it on the U: drive, and creates private folders with the correct ACL permissions.
I read through quite a bit of troubleshooting information trying to get Powershell to fully expand the output of commands from a MS Online Service Module—in this case, Exchange Online.
I kept getting outputs with ellipses:
Get-DistributionGroup -Identity examplegroup@example.com | Format-table -Wrap -Autosize -Property Name,Acceptmessagesonlyfrom
AcceptMessagesOnlyFrom
----------------------
{Office of the President, Bob Smith, Bob Jones, Bob Doe...}
The way Powershell is handling this output is frustrating to me. I am not used to a scripting language cleaning up its output to look pretty, unless I specify some filtering options.
I played around with multiple versions of -wrap or -autosize and a ton of other arguments thinking it was an issue with format-table. The problem in this case is actually a quirk in the MS module, not the Powershell format-table or format-list command.