Category Archives: PowerShell

O365 – How To Add Proxy Addresses To AD Groups From CSV File With PowerShell

When using Azure AD Connect with Office 365, you will find that many of the mailbox and distribution group attributes cannot be set in the Office 365 portal.  When you try to update the attributes, you will see an error such as the one shown here:Update Error
Since this is an attribute that is synchronized from AD via AAD Connect, it must be updated in Active Directory and the new values will then be synchronized to the Office 365 Portal.

I recently needed to add a second e-mail address alias to a number of distribution groups.  Below are the steps I took using PowerShell to update the groups.

1. Create a CSV file with two columns, Name and ProxyAddresses.  Populate the appropriate cells with the distribution group name and the proxy addresses separated by a semi-colon.  The proxy address with the capitalized SMTP will be the primary e-mail address for the group and will be used as the ‘sent from’ address.  Save the file and note the file location.CSV File

2.  Create a PowerShell script as follows changing the file name and location as needed:

Import-Csv C:\Scripts\DistGroups.csv | ForEach-Object{
  $name = $_.Name
  $proxy = $_.ProxyAddresses -split ';'
  Set-ADGroup -Identity $name -Add @{proxyAddresses= $proxy}

3.  Run the script.  Open a distribution group in AD, navigate to the Attribute Editor tab and scroll down to the proxyAddresses attribute.  Both  e-mail addresses will show.ProxyAddresses

4.  In the O365 Exchange Admin Center, navigate to Recipients > Groups.  Edit the distribution group and select the E-mail Options page to see that both the e-mail addresses are showing.

PowerShell Search For Specific Files

One of our systems used old, inefficient technology (you have systems like that, right?).  The system would drop thousands of files into a folder to be reviewed and relocated based on criteria provided by the finance team.  Our developers were working on a way to add automation to the process, but it was not a high priority project.

Until the automation project could be completed, the finance team asked if we could help by setting up a system to parse through the files and provide them with a daily report of unprocessed files.

I created and scheduled a PowerShell search script based on the requirements which would find the unprocessed files, export the data to a .csv report file and send an e-mail to the team with the location of the daily report.  Problem solved.

Below is the PowerShell code that I used to make it happen.

$Path = "\\dom\shares\prod\fin"
Get-ChildItem -Path $path -Filter "*op*.txt" -Recurse `
| Select-Object -Property Name, DirectoryName, @{Name="Size (KB)"; Expression={"{0:0.00}"-f $_.length/1024 }}, LastWriteTime `
| Export-Csv "\\dom\shares\prod\fin\report\UnprocessedDailyReport.csv" -NoTypeInformation


Get User Account Expiration Date

Our security team implemented a rule that all vendor user accounts must be reviewed and renewed every 30 days.  To facilitate this process, I created a script to automate retrieval of the expiration date of the vendor accounts based on the description and/or title fields which is where the company name of the vendor was stored.  The resulting .csv file was then used to review the accounts and to open a ticket for renewal of the current accounts. Continue reading Get User Account Expiration Date