Todd's Blog

Todd's Tips for System Adminstrators

  • TechDays
  • Speaking Engagements
  • Contact Me
  • About Me

Connect

  • LinkedIn

Powered by Genesis

Saving an Office 365 PowerShell Export with the Current Date in Filename

posted on May 1, 2014

Powershell Logo

Working with PowerShell for my Office 365 projects, I have created a couple of scripts to provision users and to run through and assign users specific address books.

One of things I do is dump all my new users to a CSV file. However, I want a file created each time its run showing me which users are created.

First thing is to make a variable with the current date in the format you would like.

$CurrentDate = Get-Date -format dd.MMM.yyyy

Next I create the filename in a variable using the combination of the filename I want and the date variable.  (The code is all one line, but might not display that way here.)

$filename1 = "c:\Export\Users\Provision-Student" + $CurrentDate + ".csv"

Finally I then call the file by piping a command to export-csv.

Get-MsolUsers -All Domain "contoso.com"| Select UserPrincipalName | export-csv -path $filename1


I schedule this to run once daily and every day I have a file all my users in the contoso.com domain.

In another post I’ll show you how to clean up these files so you aren’t overrun with them.

Filed Under: Technology Tagged With: 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