Confusias
Confusias

Reputation: 11

Office 365 New-InboxRule Powershell script

I'm trying to create a little script to quickly create simple inbox rules on Office 365 using PowerShell. Thus far I have the following syntax that is getting hung up by what I have in the '-MoveToFolder' parameter. I've started repeating steps so it's time to ask for help...

$UserCredential = Get-Credential
$MoveToFolder = Read-Host -Prompt "Destination folder name"
$FromAddressContainsWords = Read-Host -Prompt "Sender info"
$UserEmailAddress = $UserCredential | %{$_.UserName}
Connect-MsolService -Credential $UserCredential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -AllowClobber
New-MailboxFolder -Parent :\Inbox -Name "$MoveToFolder"
$MAlias = Get-Mailbox -Identity "$UserEmailAddress" | %{$_.Alias}
New-InboxRule -Name $MoveToFolder -Mailbox $UserEmailAddress -FromAddressContainsWords $FromAddressContainsWords -MoveToFolder ${'$MAlias:\Inbox\$MoveToFolder'}
Remove-PSSession $Session

Upvotes: 0

Views: 2497

Answers (1)

Confusias
Confusias

Reputation: 11

Nevermind, I don't need any of you! This time... Fixed the broken parameter and all is well now.

-MoveToFolder "$($UserEmailAddress):\$MoveToFolder"

Upvotes: 1

Related Questions