Solved: Getting a user’s Distribution Group Memberships

Posted on

It’s surprisingly hard to get back a listing of all of a particular user’s Exchange Distribution Group Memberships. The strange thing about this is that you can very easily get a list of all of a user’s AD Security Groups using

Get-ADPrincipalGroupMembership

. If this works for your purposes, great, but if what you really need is a report of all of a user’s / mailbox or resource mailbox Distribution Group membership, I’ve come up with the following.

get-distributiongroup | ForEach-Object {
$groupName = $_
Get-DistributionGroupMember -Identity $groupname.Name | ForEach-Object{
    [pscustomObject]@{GroupName=$groupname;groupMember=$_.Name}
    }
} | Group-Object -Property GroupMember | 
    Select-object Name, @{Name=‘Groups‘;Expression={$_.Group.GroupName}}

Whoa! What’s happening there?

Here’s the walkthrough of why this works:

  • We’re getting a big list of all of the distribution groups
  • for each, resolving the full membership of each group
  • For every entity we discover who is a member of this group, we create a custom object of “username,groupname”
  • Once this finishes, we send this to the Group-Object command to let it pick out every unique user
  • Then gather all of their memberships using a calculated property
  • We then can send this on to a CSV file, to get an output like this.
#TYPE Selected.Microsoft.PowerShell.Commands.GroupInfo
"Name","Groups"
"Stephen","Group_1 Group_2 OtherFolks"
"Lenna.Paprocki","Group_2 OtherFolks"
"James.Butt","Group_2 OtherFolks"
"Josephine.Darakjy","OtherFolks"

In my opinion, XML would be the best way to display this info, rather than a CSV. Additionally, it would be very cool to have a lighter weight cmdlet to return just the Distribution Group membership of one user. If I come up with this approach, I’ll be sure to update this.

Hope you enjoy!

Migrating to your own WordPress.org account – things that will suck and how to avoid them

Posted on

I’ve recently been in the process of migrating my blog off of WordPress.com hosting to my own WordPress.org account.  I tried a few things, a number of which did not work well, and I hope to help you avoid them if you try the same thing too.

After installing WordPress on a localhost / Linux LAMP setup (Linux Apache MySql PhP) you’re prompted for credentials when uploading content or plugins

This one is super annoying.  You’ll basically see a message like this whenever you try to install a new plug-in, and have to put in your  Linux credentials.

Whoa whoa whoa, contact my host?  I am the host.  Uh-oh.
Whoa whoa whoa, contact my host? I am the host. Uh-oh.

–Whats going wrong

What happens here is that if you follow the instructions in this page for setting up WordPress on a LAMP stack, you’ll end up with WordPress installed to /var/www and all of the files and folders there owned by your user account.  This means that when you try to upload files, Apache, the Linux Web Service, which runs with the user account www-data will not have any permission to this path.  Hence the prompt for credentials.

–How to fix it

This is simple.   Read the rest of this entry »

Is your SCCM SQL stuck in Evaluation mode? Don’t despair!

Posted on

Have you ever wondered what happens when you install SCCM 2012 or 2007 on top of SQL and choose ‘Evaluation mode’, then forget to enter the SQL key?

SQL will turn off the SQL Database Service on day 180, and never turn back on until you license it

How’s that for getting your attention?

Recently at a client, my contact was searching for their install keys, and promised to provide them later. No problem, I said, and proceeded to install both ConfigMgr 2012 R2 and SQL 2012 SP1 in evaluation mode. Typically what would happen here is that after a week or so, the VAR would get back to us with some keys…This time however…

The big rub was that this was an educational institute. They are sold licenses in different quanities and at different rates than your typical enterprise or SMB, the sorts of customers I deal with much more often. Those larger firms often buy a bundle of SQL licenses, and I’d just use one of them, which would get re-added / comped to their license pool the next time they re-upped their licenses. Schools don’t typically need SQL Server, relying instead on Postgresql or MySQL (shudder) or even worse, Oracle.

I contacted Microsoft about my dilemma and posted online, I was told that System Center does include a special SQL installer that won’t prompt you for a key, meaning that there are no install keys for me to find in my Volume License account. What should happen is that if you use the right iso, it will contain your own license key for SQL pre-embedded, and you can actually see it when you run the installer.  However, this installer will detect pre-existing SQL features, and will dump/not display the license info if it detects any.

When I posted online about it people told me to backup my SQL Server DBs, delete my SQL install, then reinstall using the special installer ISO (and hope that SCCM’s accounts restore without any pain).

Thanks to the help of my friend, MCT and SQL Badass Sassan Karai, we found a better way.

Read the rest of this entry »

Automatically Delete old IIS logs w/ PowerShell

Posted on

I’ve seen one to many servers hobbled by a run-away IIS installation. By default, if IIS is enabled and allowed to store its log files, it’s only a matter of time before it consumes every scrap of space on the C:, leaving no room even for a user profile to be created! When this happens, no one can log onto the machine who hasn’t already stored their profile before. It’s sad. It’s so sad, it even has a frowny face on Server 2012 systems.

windows-server-2012-rds-user-profile-service-failed-the-sign-in

Never again will IIS be allowed to tyrannically absorb all file system space! I wrote this script for a client to remove IIS files older than 30 days. Update the $LogPath to point it at your IIS log’s directory, change the $maxDaystoKeep value and the $outputPath value to tell the script where to put your logs. If files exist that are older than 30 days, they’ll be tossed, and a nice log entry created. If not, an entry will be added to the log stating ‘no files to delete today’ instead.

$LogPath = "C:inetpublogs"
$maxDaystoKeep = -30
$outputPath = "c:CleanupTaskCleanup_Old_logs.log"

$itemsToDelete = dir $LogPath -Recurse -File *.log | Where LastWriteTime -lt ((get-date).AddDays($maxDaystoKeep)) 

if ($itemsToDelete.Count -gt 0){
    ForEach ($item in $itemsToDelete){
        "$($item.BaseName) is older than $((get-date).AddDays($maxDaystoKeep)) and will be deleted" | Add-Content $outputPath
        Get-item $item | Remove-Item -Verbose
    }
}
ELSE{
    "No items to be deleted today $($(Get-Date).DateTime)"  | Add-Content $outputPath
    }
 
Write-Output "Cleanup of log files older than $((get-date).AddDays($maxDaystoKeep)) completed..."
start-sleep -Seconds 10

I deployed this as a Scheduled Task and it’s running wonderfully thus far. Enjoy!

Move old photos out of DropBox with PowerShell to free up space

Posted on

I love dropbox, we all love Dropbox, it even comes preinstalled on our phones!

Sadly, it can be irritating when you get notices like this on the desktop

Dropbox Nag Screen

I noticed one day that my DropBox camera roll folder was using up the vast majority of my free space, something like 60 or more percent! Since I’ve got a 9 month old, its no wonder. I am constantly recording pictures and videos of her, so it’s a matter of course.

If we could move all files older than three or four months out of the Dropbox ‘Camera Uploads’ folder, we could really free up some space! Additionally, I wanted to backup my files from DropBox onto another Storage Provider (OneDrive) as well as move a copy onto my backup drive. To solve all of these needs, I wrote a PowerShell script which can run as a scheduled task to handle moving the items out of the Camera Uploads folder. This can be run on any system that you’ve got the DropBox desktop client installed.
Read the rest of this entry »