Collecting Accounts for Deletion
We have just migrated our school's student email account from Hotmail to Outlook Live. It turns out that we have more accounts than can be comfortably managed with Remote PowerShell. Just trying to define a custom attribute causes PowerShell to crash on a server with 16 cores and 48GB of RAM. I would like to "cull" out the unneeded accounts to make this more manageable. Our current naming convention is firstname.lastnamennn@students.domain.edu, where "nnn" is the last 3 digits of their ID, and is always numeric. Is there any way I can filter and delete any account that does not use this format? It would be beyond helpful if someone could point me in the right direction. Thanks, Jeff Bradley
June 21st, 2011 11:35pm

This should be doable. What is the "ID" that you refer to?Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
Free Windows Admin Tool Kit Click here and download it now
June 22nd, 2011 2:03am

Ed, The part of the email address before the "@<domain name>", like in Fred.Flintsone123@students.camdencc.edu , I would be referring to the "Fred.Flintsone123" part. Thanks, Jeff Bradley
June 22nd, 2011 2:43am

According to RFC 821 that's known as the "local-part". But that's not what you were talking about, you said that has the last three digits of the "ID". I'll give you clues to how you can do this in PowerShell, but you're going to have to code it yourself. First get all mailboxes, like: $Mailboxes = Get-Mailbox Next iterate through them. ForEach ($Mailbox In $Mailboxes) { You can get the primary SMTP address's local part. $Local = $Mailbox.PrimarySmtpAddress.Local Then you can do a string comparison of that local part to see if it's in the format you expect, and based on that comparison, delete it. I recommend you use the -WhatIf:$True switch on the Remove-Mailbox cmdlet until you're sure you're only going to be deleting the mailboxes youwant, and you'll probably want to use the -Confirm:$False switch so you don't have to personally acknolwledge each deletion. Good luck!Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
Free Windows Admin Tool Kit Click here and download it now
June 22nd, 2011 3:47am

My apologies. You are correct about the ID. The ID is actually a six digit student ID assigned to each student on enrollment. We use the last 3 digits of that and append it to their first and last names to try to keep their email addresses unique. Is there any way to test the Primary.SmtpAddress.Local string to see if it ends in three numeric characters? This would mean that it’s probably a good address. Thanks again, Jeff Bradley
June 22nd, 2011 4:58am

There are all kinds of string manipulation functions in PowerShell. This book is great: http://www.barnesandnoble.com/w/windows-powershell-in-action-bruce-payette/1008017906?ean=9781932394900&itm=1&usri=powershell%2bpayette And there are plenty of Internet-based resources to help you.Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
Free Windows Admin Tool Kit Click here and download it now
June 22nd, 2011 8:20am

Thank you for the recommendations. I will find those resources. I have also found method of isolating the string I need and testing it. However, I am having problems with the line: $Mailbox.PrimarySmtpAddress.Local If all of my mailboxes are in an array called $mbx, and, for example, $mbx[4] returns a mailbox, shouldn't the line: $Local = mbx[4].PrimarySmtpAddress.Local return something? It returns nil. If I use it without the ".Local", it returns the full email address, including domain name. Also, can you recommend a place where can I get a list of mailbox parameters, and how to display them? Thanks, Jeff Bradley
June 22nd, 2011 6:33pm

It's not an array, it's a collection, but if you go back and reread my post, you'll see that the collection is $Mailboxes and when you iterate through the collection each individual mailbox is $Mailbox. You can test by assigning $Mailbox to a single mailbox. That's a good way to start before looping through all of them.Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2011 1:35am

Hi, Do you have any update? ThanksPlease remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
June 24th, 2011 10:26am

Not really. I am still looking for a way I can isolate a single mailbox from the collection "$mbx" for testing. I created $mbx with "get-mailbox". I am told that it is not an array, but I don't know how I can grab a single mailbox from it so I can test certain elements of a script. Thanks, Jeff Bradley
Free Windows Admin Tool Kit Click here and download it now
June 24th, 2011 10:35am

On Wed, 22 Jun 2011 15:33:20 +0000, JeffreyBradley wrote: > > >Thank you for the recommendations. I will find those resources. I have also found method of isolating the string I need and testing it. > >However, I am having problems with the line: $Mailbox.PrimarySmtpAddress.Local > >If all of my mailboxes are in an array called $mbx, and, for example, $mbx[4] returns a mailbox, shouldn't the line: > >$Local = mbx[4].PrimarySmtpAddress.Local > >return something? It returns nil. If I use it without the ".Local", it returns the full email address, including domain name. You're missing the "$" in the "$mbx[4]". :-) >Also, can you recommend a place where can I get a list of mailbox parameters, and how to display them? get-mailbox <name> | fl * -force But a mailbox is "possession" of a user, so to see the rest of any user properties you need to "get-user <name> | fl * -force". To see what methods and properties are present, use "get-mailbox | gm". --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
June 25th, 2011 1:01am

On Fri, 24 Jun 2011 07:35:37 +0000, JeffreyBradley wrote: >Not really. I am still looking for a way I can isolate a single mailbox from the collection "$mbx" for testing. I created $mbx with "get-mailbox". I am told that it is not an array, but I don't know how I can grab a single mailbox from it so I can test certain elements of a script. If you're expecting to deal with a variable that's a collection of objects you can't simply assign the results of an operation to a variable if the operation returns just a single result. You have to add whatever's returned by the operation to the array. $result = @() # create an empty array $result += operation # works if "operation" returns one or more # results This should remove the mailboxes that have non-compliant e-mail addresses. Change the "$true" to "$false" if you really want the mailboxes removed. :-) The regex matches the pattern "<beginning-of-string><not-digits><period><not-digits><three-digits><end-of-string>". This makes the assunmption that none of the "names" have digits in them. Get-Mailbox -resultssize unlimited | foreach { if ($_.primarysmtpaddress.local -notmatch "^\D+\.\D+\d\d\d$") { $_ | remove-mailbox -whatif:$true } } --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
June 25th, 2011 1:21am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics