Sometimes 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.