Custom automation script based on empty attribute

Custom automation script based on empty attribute

Hello All,

I have been fighting for days to figure out how to get a custom automation PowerShell script to run for users with an empty attribute. The empty attribute report works great and finds the users needed, but then I am not able to get my custom automation script to run successfully. I really think the issue is that I am trying to append the %username% attribute to @company.com, so ADManager is literally trying to find a user called %username%@company.com, which isn't a valid username. 

I am hoping that someone has done something similar and can help figure out where I am going wrong. 


The operation couldn't be performed because object %username%@company.com couldn't be
found

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Automation Script: Powershell.exe -File EnableRemoteMailbox.ps1  %username%

PowerShell Script: EnableRemoteMailbox.ps1

# Start logging
Start-transcript C:\Temp\EnableRemoteMailbox_Log.txt

# Load the snap-in for the Exchange commands
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;

# Enable Remote Mailbox routing needed for O365
Enable-RemoteMailbox -Identity %username%@company.com -RemoteRoutingAddress %username%@company.mail.onmicrosoft.com

# Stop logging
Stop-transcript