The following Office 365 powershell script helps you to dump UserPrincipalName of all users to a file

First step of procedure is to connect to Azure PowerShell, refer here for procedure

Once we have successfully connected to Office 365 Azure PowerShell, use the following script

#Step1 : Get list of all the users in a variable named

$UserList $UserList = Get-MsolUser -all

#Step2 : Create a csv file to dump all the information

$filepath= “C:\UPN.csv” $outFile=$filepath -f (Get-Date)

#Step 3: Query each user for in $UserList for UPN and store it in file

foreach ($u in $userList)

{ $upn = $u.UserPrincipalName

Out-File -FilePath $outfile -Append -NoClobber -InputObject $upn

}

Hope this scripts helps you, for any more help regarding this or to report any other issue, feel free to start a new thread on our forum

 

The following two tabs change content below.
An automobile enthusiast at heart and computer geek by profession, started my Career with MS in 2005.Left Jobs and started Pledge Technologies (the parent company to Grishbi) back in 2009.We have been providing IT consulting to various Small and Medium businesses across US and UK since then.Our company specialises in Microsoft Server technologies like AD, Exchange, the rest and with numerous Office 365 migrations under our belt, we quite an expert with that too. Whatever we learn in our day to day life, we share it back on Grishbi as a Thank for all the love and support our customers have given us.
%d bloggers like this: