Todd's Blog

Todd's Tips for System Adminstrators

  • TechDays
  • Speaking Engagements
  • Contact Me
  • About Me

Connect

  • LinkedIn

Powered by Genesis

Generating a CSV file from Office 365

posted on September 2, 2013

Powershell LogoSometimes you need to run a command against multiple users. Maybe like me, you have 40,000 to run against. Entering each user name manually sucks, using the GUI would be unusable.

To generate a CSV file that lists all users in a particular domain in Office 365:



Get-MsolUser -DomainName "contoso.com" -All | Select UserPrincipalName |Export-Csv -path "C:\Exports\MyNewCSVFile.csv"

Which in turn generates a file with a list of the UPNs in Office365.

From there I can the run a command which sets something against each user in my Office 365 tenant.

Import-Csv -Path "C:\Exports\MyNewCSVFile.csv"  |%{Set-MsolUser -userPrincipalName $_.UserPrincipalName -"Rest of the commands you want here"}

Pretty simple and straight forward. If you want to add say a date to the filename add this to the script.

$CurrentDate = Get-Date -format dd.MMM.yyyy
$filename = "C:\exports\yourfile" + $CurrentDate + ".csv"

This will allow you to create a variable $filename which will contain your file name and a date added to it.

Now for the path variable you can put $filename rather than the full c:\xxxx information. It also allows you to use it in a script that can be automated and you will have files left behind to look it for checks.

 

 

Filed Under: Technology Tagged With: Exchange Server, Office 365, Powershell

About Todd Lamothe

Recent Posts

  • Office 365 – Creating Custom SKUs
  • Setting a Default Printer in Windows 10
  • Deploying Windows to the Correct Drive in Configuration Manager
  • Surface Pro 4, Surface Dock and DVI Problems
  • Enabling UEV in Windows 10 1607

Recent Comments

  • Moore Details on Setting up a Delayed Charge in Quickbooks Online
  • MCP Exam Training on Using PowerShell to Get a List of Groups from Active Directory
  • Kac on Setting up an Office 2010 KMS Host Server
  • prabumedia.com | Pilih lisensi MAK atau MKS untuk aktifasi produk Microsoft ? on Setting up a KMS Server
  • prabumedia.com | Pilih lisensi MAK atau MKS untuk aktifasi produk Microsoft ? on Setting up an Office 2010 KMS Host Server

Archives

Categories

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org