Thursday, September 19, 2013

Assign a Move-To-Archive tag to a specific mailbox folder in Exchange Online/Office 365

You have an Exchange Online environment, and want to apply a move-to-archive tag to a specific folder in some user mailboxes.

GIVENS:
- Retention Policy tags do not allow a Move To Archive action.
- Default Policy tags apply to an entire mailbox.
- Personal tags are not administratively set or enforced.

SCENARIO:
- A client of mine required that all items in a specific folder be moved to the archive after a specifc time period, and there should be no other automatic archive or retention actions for any other folder.
- The users at this client are unlikely to ever reconfigure or explore their archive settings and cannot be asked to apply any personal tags themselves.
- There are too many users to expect that an IT person would manually apply the personal tag for each user.
- It is OK that the users have the option to change the archive settings on their mailbox; given the above there is no worry that they will do so.

I found and reviewed two very helpful pages that almost solved this for me, but didn't quite bring the runner all the way home. (I can't emphasize enough though, there is no way I could have done this without them.)

My script, with the required changes -
#Connect to Exchange Online for Remote PowerShell
$cred = Get-Credential
 
$Office365 = @{
configurationName = "Microsoft.Exchange"
connectionUri = "
https://ps.outlook.com/powershell"
credential = $cred
Authentication = "Basic"
AllowRedirection = $true
}
 
$s = new-pssession @Office365
Import-PSSession $s


##########################################################################################################################################################################################################################################
# The script requires the EWS managed API, which can be downloaded here:
#
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=c3342fb3-fbcc-4127-becf-872c746840e1
# This also requires PowerShell 2.0
# Make sure the Import-Module command below matches the DLL location of the API.
# This path must match the install location of the EWS managed API. Change it if needed.
[string]$info = "White" # Color for informational messages
[string]$warning = "Yellow" # Color for warning messages
[string]$error = "Red" # Color for error messages
[string]$LogFile = "C:\Temp\Log.txt" # Path of the Log File
function StampPolicyOnFolder($MailboxName)
{
Write-host "Stamping Policy on folder for Mailbox Name:" $MailboxName -foregroundcolor $info
Add-Content $LogFile ("Stamping Policy on folder for Mailbox Name:" + $MailboxName)



#Change the user to Impersonate
$service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress,$MailboxName);



#Search for the folder you want to stamp the property on
$oFolderView = new-object Microsoft.Exchange.WebServices.Data.FolderView(1)
$oSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$FolderName)

$oFindFolderResults = $service.FindFolders([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$oSearchFilter,$oFolderView)

if ($oFindFolderResults.TotalCount -eq 0)
{
Write-host "Folder does not exist in Mailbox:" $MailboxName -foregroundcolor $warning
Add-Content $LogFile ("Folder does not exist in Mailbox:" + $MailboxName)
}
else
{
Write-host "Folder found in Mailbox:" $MailboxName -foregroundcolor $info
Add-Content $LogFile ("Folder found in Mailbox: " + $MailboxName)



#PR_ARCHIVE_TAG 0x3018 - We use the PR_ARCHIVE_TAG instead of the PR_POLICY_TAG
$ArchiveTag = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x3018, Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary);



#PR_RETENTION_FLAGS 0x301D
$RetentionFlags = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x301D,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);



#PR_ARCHIVE_PERIOD 0x301E - We use the PR_ARCHIVE_PERIOD instead of the PR_RETENTION_PERIOD
$ArchivePeriod = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x301E,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);



#Change the GUID based on your policy tag
# The Guid of our 9-month Move To Archive retention tag (in our O365 tenant) is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
$ArchiveTagGUID = new-Object Guid("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}");



#Bind to the folder found
$oFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$oFindFolderResults.Folders[0].Id)
$oFolder.SetExtendedProperty($ArchiveTag, $ArchiveTagGUID.ToByteArray())



#Same as that on the policy - 16 specifies that this is a ExplictArchiveTag
$oFolder.SetExtendedProperty($RetentionFlags, 16)



#Specify the days until the tag's action occurs (i.e., the retention period before the items are moved to the archive)
$oFolder.SetExtendedProperty($ArchivePeriod, 275)
$oFolder.Update()



Write-host "Retention policy stamped!" -foregroundcolor $info
Add-Content $LogFile ("Retention policy stamped!")
}



Start-ManagedFolderAssistant -Identity $WindowsEmailAddress

$service.ImpersonatedUserId = $null
}



#Change the name of the folder. This is the folder the properties will be stamped on.
$FolderName = "Deleted Items"

Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll"

$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013)


# Set the Credentials
#$service.Credentials = new-object Microsoft.Exchange.WebServices.Data.WebCredentials("UserName","Password","Domain")
$service.Credentials = new-object Microsoft.Exchange.WebServices.Data.WebCredentials($cred)



# Change the URL to point to your cas server
#$service.Url= new-object Uri(
http://YOUR-CAS-SERVER/EWS/Exchange.asmx) -- presumably this line works for On-Prem Exchange, but we're using Exchange Online/O365
$service.Url= new-object Uri("https://outlook.office365.com/EWS/Exchange.asmx")


# Set $UseAutoDiscover to $true if you want to use AutoDiscover else it will use the URL set above
$UseAutoDiscover = $false



#Read data from the UserAccounts.txt.
#This file must exist in the same location as the script.
import-csv UserAccounts.txt | foreach-object {
$WindowsEmailAddress = $_.WindowsEmailAddress.ToString()
if ($UseAutoDiscover -eq $true) {



Write-host "Autodiscovering.." -foregroundcolor $info
$UseAutoDiscover = $false
$service.AutodiscoverUrl($WindowsEmailAddress)

Write-host "Autodiscovering Done!" -foregroundcolor $info
Write-host "EWS URL set to :" $service.Url -foregroundcolor $info
}



#To catch the Exceptions generated
trap [System.Exception]
{
Write-host ("Error: " + $_.Exception.Message) -foregroundcolor $error;
Add-Content $LogFile ("Error: " + $_.Exception.Message);
continue;
}



StampPolicyOnFolder($WindowsEmailAddress)
}



Remove-Pssession $s

NOTE: The 'Start-ManagedFolderAssistant' function will force the MFA service on the server to run immediately against the specified mailbox, in order to apply the changes immediately, instead of whenever the service would get around to that mailbox through the course of its routine operation.

When I tested my code that line threw an error that it was not recognized as a valid commandlet. I believe that was due to the context I was running the script in, and I either need to run the script from my MSOL PS prompt, or relocate the command elsewhere in the script above.

When I ran the script above though, and then connected to Exchange Online in an MSOL PS cmd window and ran the Start-ManagedFolderAssistant command there, afterward I closed & restarted Outlook and the changes to my mailbox WERE evident.


PS: Sorry for the poor formatting, I'm having ridiculous trouble trying to clean the results up from pasting the code.

PPS: Holy Cow - I knew it had been a long time, but 2 YEARS since I updated this blog? Wow, Facebook really is wiping out the rest of the web, starting with me....

Tuesday, July 10, 2012

Frustration and the Gym


The definition of insanity is doing the same thing over and over and expecting different results.


Who are you going to believe, me or your lying eyes?

Leaving the gym tonight I was reminded of the above two quotes, and I’ll explain here how they tie together.

Three or four years ago I decided to begin going to the gym, to try and improve both my health and my physique. I went somewhat regularly – usually 2 or 3 days/week – until last August. Last August I became very busy and stopped finding time for the gym.

Last week I resumed my workouts, and since Wednesday I’ve gone to the gym 5 out of 7 days. According to my log at the Nike.com website (iPod tracks my workouts and uploads them automatically), I’ve run about 13.8 miles since Wednesday. Untracked by the iPod are the weight machines, that I also use each visit.

Even after I’d been going to the gym pretty regularly for two years I didn’t *look* any more fit or trim than I did before I’d started. And after hitting the weight machines and then running 3 miles tonight, I looked down at my pathetically sweaty and panting self, and I saw the same Homer Simpson physique that I’ve had for my entire adult life.

Working out doesn’t make me trimmer; it simply increases my appetite, cancelling out any slimming effects the additional exercise might have bestowed upon me.

But, thanks probably to cultural conditioning I still believe there must be some health benefits to the exercise regimen, despite my visibly unchanging fat torso. (“Who are you going to believe, me or your lying eyes?”)

And I keep returning to the gym, plugging away, and don’t intend to stop. (“The definition of insanity is doing the same thing over and over and expecting different results.”)

I believe the only way I’ll ever slim down would be to eat more foods I don’t really like, and less foods I do like. Fifteen years ago I dramatically reduced my fast food and soft drink intake – that resulted in a one-time weight loss. I still prefer carbohydrates over other foods, and have no desire or intention of diving into veggies or salads. Thinking I’ll do that is unrealistic. When I’ve tried to eat healthier the effort usually fails within 3 meals. It’s simply not sustainable.

So it looks like the exercise alone is never going to make me slim, and yet I’ll keep doing it. I guess that makes me insane, at least on some level.

:-(




Monday, June 11, 2012

A very funny snippet from one of my current favorite TV shows

Sheldon: All right, I’ve taken the liberty of drafting these workflow charts which outline our various duties and the path we will follow as we develop our ground-breaking new app.

Raj: Hey, why am I in charge of phone support? Seems a bit racist.

Sheldon: A customer service representative with an Indian accent will create the impression we’re a vast enterprise that uses overseas call centres.

Raj: Oh. Very clever. But still racist.

Sheldon: Duly noted, Steve from Wichita.

Tuesday, June 05, 2012

I am victorious, again

Lately our house has bred friction due to Nate, Maren, and Jess all wanting to use the computer at the same time. Yeah, I know, we should all suffer such tragedies... Nate decided he wanted to use his accumulated allowance money to buy himself a laptop.

Instead, on May 5th I went to Microcenter and bought components to build a modern desktop PC to keep in the den for Nate & Maren to share, and something to keep them off of Jess' laptop.

Parts list:
  • Gigabyte Z77M-D3H motherboard
  • Seagate ST310005N1A1AS HDD - 1Tb, 7200rp
  • Corsair 8Gb DDR3 RAM
  • Intel Core i5-3570k CPU, retail box
  • Sony bulk DVD-RW
  • CoolerMaster 500w PSU

I assembled the components, re-using an old case and power supply (PSU), but otherwise using all new parts. (Planned to return the PSU if I could use the old.) The system frequently locked up, with no rhyme or reason.

Over the last month I didn't have time to focus on the problem, but occasionally tried to figure it out.

I tested the RAM for 7 hours, no errors. I ran a disk utility from the hdd manufacturer, found no errors there. I booted off of Live CDs, the system still locked up sometimes.

Over the weekend I returned to Microcenter and discussed the problem with one of their system builders. After describing everything I'd done so far, he concluded that given everything I'd tried so far, maybe the motherboard itself was bad, and suggested I bring it back for an exchange.

I returned the next day and exchanged the motherboard. Microcenter was great about the whole process.

After swapping the motherboard the system still locked up inexplicably. I then swapped the PSU with a brand-new PSU. That didn't help either.

I flashed the BIOS to the latest BIOS revision. Still no help.

I finally found the solution on Sunday night, buried deep in a British forum focused on Gigabyte motherboards.
- http://forums.overclockers.co.uk/showthread.php?t=18396884&page=11

Sunday night I raised the BCLK setting in the BIOS from the default 100.00 to 100.10, and the machine has been on since then, and hasn't locked up yet.

:-)


Friday, June 01, 2012

I AM VICTORIOUS


Two or three years ago I became the thrilled owner of a brand-new Hewlett-Packard (HP) Photosmart Premium Wireless All-in-One printer. I loved this printer - inexpensive ink, wireless-N, built-in quick-forms, touch-screen, scan-to-web-page interface, and on and on.

My only criticism was that the platen was not legal-size, but that only matters very infrequently.

Then last fall the computer wouldn't connect to the printer. So, as I've done many times before I uninstalled the printer software, planning to reinstall and proceed as normal.

The reinstallation error'ed out.

I battle with mal-adjusted, malcontent, socially deviant computers and assorted technologies for a living, and I certainly wasn't going to just sit there and take any disrespect from that piece of plastic and silicon.

Unfortunately, the printer was winning for several months. Every so often I'd take another crack at installing the printer software, and I never succeeded. Each attempt would last several hours - the best I ever managed was to get basic printing working, but no scanning functionality was present.

Finally, today, after another prolonged battle lasting most of the day, I've defeated the programmers at HP, Intel, & Microsoft. They put up a good effort, but in the end I was able to get the printer software installed on my computer once again, with full functionality. The guys and gals that worked on the installation software will now just have to go find somebody else to push around!

And now, in case another soul comes across this post, the gory details:
Printer: HP c309g-m
OS: Windows 7 64-bit
Computer: Lenovo T420 laptop

Problem:
HP AIO installer would not run successfully. Depending on what I tried, sometimes the installer would simply begin running and then simply abort. The install program would just disappear. Other times, I'd see error messages like

"X:\hpzprl40.exe not found"

or



or

"Fatal Error"

etc....

Searching Bing or Google with combinations of terms such as HP Printer can't install fatal error c309 temp not found will result in numerous results. I spent many hours, on many days, over many months poring through the results with no success.

I tried uninstalling and re-installing various bits & pieces (anything HP-related, Adobe Flash, .NET). I tried running the installer as Administrator. I tried running the installer on 2 different graphics cards (my laptop has an NVIDIA Optimus hybrid graphics system). I tried disabling the HP Updates. I tried disabling my firewall.I tried capturing the extracted install files before the installer failed, and then running setup directly from those files instead of letting the installer extract them and then run the temp files.

Nothing helped.

Finally, today I found a post on the Microsoft Answers message board with the answer. ( http://answers.microsoft.com/en-us/windows/forum/windows_vista-hardware/hp-photosmart-printer-software-installation/8681fee2-296b-4927-bc88-eeb15ade0416 )

I updated the Intel wireless driver for my laptop, and afterward was able to install the HP printer software successfully. Hallelujah!

(I still haven't re-installed Flash, but I don't think that has anything to do with the problem.)

Wednesday, May 30, 2012

Fantasizing

My latest fantasy:
1) Win a life-changing lottery pool.
2) Hire gardener/landscaper/yardguy.
3) Quit job.
4) Start a Computer Geek/Fix-it service providing services to the public, according to the following:
---- Unprofitably low rates - maybe $25 flat-rate or something like that.
---- Rather than accepting payments, have a computer set-up on the desk that 'customers' use to make online donations to a charity they choose from a list of charities I've selected.
--- Once the person needing assistance makes the donation, I fix their computer.

Keeps me feeling productive, improves the world, and hopefully is more relaxing for me than actually working for a business that must turn a profit.

And of course there's always my fallback-fantasy - retire, move to the Caribbean, and take a job as a taxicab driver for cruise-ship passengers, ferrying the tourists between the dock and the various on-shore attractions.


Thursday, April 19, 2012

Back from the grave.

Keeping this short and sweet:

- a coworker needed my help to access Google Analytics. That reminded me of this blog's existence, and I realized I've neglected the page for almost a year. So I'm back.

- recently decided to learn guitar. Bought a used Yamaha. Have spent some time over the last two nights beginning to teach myself how to play. After about an hour last night, I noticed the tips of some of the fingers on my left hand were sore and beginning to be calloused. I felt pride in that! :-)

- I saw an old post on this blog about an Asus laptop I bought from Woot, that was being sent back for repair. I never updated that post. End result - Asus hardware is awesome. Asus service and support is every bit as BAD as their products are good. We ended up returning the laptop to Woot for a full refund, less my shipping costs to Asus for unsuccessful repairs.

I still love Woot, but have less respect for Asus than I had previously.

- There was also an old post about Bioshock on the PS3. I still haven't made time to continue playing much, but before I stopped playing I found an effective solution for the motion-sickness problem: Sea-Bands. I can't explain why they work, and if the relief is psycho-somatic I don't care. They DO relieve the problem, at least for me. While I don't understand accupressure I'm happy to benefit from it.

-- Lastly - today is Maren's Birthday! Happy Birthday Maren!!!!!