Thursday, November 18, 2021

Sometimes you can't figure out the syntax...

 I know, I know, another work post. But it really has been taking up a lot of my mind and time lately. I worked at my previous job for over 11 years, and I was always part of a team of many other people with the exact same role as I had. So I definitely took it for granted that I could take time off at almost any time, provided we weren't all off at the same. Or that I could ask a co-worker a question about the issue at hand, or how to resolve something, or bounce ideas off of them. At my current job, I am one of two systems engineers, there's a Database Admin, and 3 help desk techs. And the other systems engineer is also the networking guy and he mostly deals with maintaining the hardware and server side of the systems work. I manage the email system exclusively, and the cloud presence(Azure AD, Office 365, Intune endpoint management, Microsoft licensing, etc.) almost exclusively. All this is to say that I really don't have overlap in most of my functions with anyone else on my team. So anything that falls in my realm, I pretty much have to figure out myself. When I'm trying to figure something out, or don't know how to do something, there's no one to ask or bounce ideas off of. Aaaaaand, I'm the end of the line for anything email, Office 365, Azure AD, etc. Recently we ran into a situation where after the migration into our M365 environment from GSuite, it became apparent we needed to convert most of our newly migrated M365 groups into Distribution Lists (DLs). I figured most of that out, wrote some scripts for it and ran them. One of the last pieces of the puzzle, was being able to set multiple owners for DLs that came from Groups with multiple owners. I could get my commands/scripts to work for setting single owners, but when I tried to set multiple owners, it would either error out, or set the first or last owner only, depending on the syntax I used in my CSV file. 

I had to move forward with the conversion, and I figured I'd run a script against all the groups with single owners first, and that would give me some time later to figure out the ones with multiple owners(about 670 DLs out of a little over 2000). This is the gist of what I am trying to do:

$owners = Import-Csv .\GroupOwners.csv
Set-DistributionGroup -Identity $_.GroupEmail -ManagedBy $_.OwnerIDs 

And the CSV looks like this: 


That works, as long as the OwnerIDs field only has 1 owner. If it has more than one, it fails. And this is the syntax for running the command with more than one owner: 

Set-DistributionGroup -Identity testDL@mercycorps.org -ManagedBy owner1@mercycorps.org,owner2@mercycorps.org,owner3@mercycorps.org

That works. But if I try and feed this a CSV with the list of DLs and owners, it won't work. I looked into it, and in a CSV file, if the field contains a comma, the escape characters are quotes. You wrap the comma in quotes, and it treats it as an ordinary character, instead of a separation in the CSV. But no matter what I tried, it would still error out. In the CSV 'OwnerIDs' field I tried:

user1@domain.org,user2@domain.org,user3@domain.org
user1@domain.org","user2@domain.org","user3@domain.org
"user1@domain.org,user2@domain.org,user3@domain.org"
"user1@domain.org","user2@domain.org","user3@domain.org"
"user1@domain.org"",""user2@domain.org"",""user3@domain.org"

And probably other variations that I can't even remember right now. All would either only read the first, last, or the whole thing as 1 invalid user/email and error, or error for some other reason. I was even working with a Microsoft engineer that wasn't very helpful...I would expect them to know their own damn syntax, but apparently not. So I resorted to a not so elegant, but nevertheless functional alternative. I just started with a txt file and copied this into it: 

Set-DistributionGroup -Identity  -ManagedBy
Set-DistributionGroup -Identity  -ManagedBy
Set-DistributionGroup -Identity  -ManagedBy
Set-DistributionGroup -Identity  -ManagedBy
Set-DistributionGroup -Identity  -ManagedBy
Set-DistributionGroup -Identity  -ManagedBy

and made 670 lines of that(copy+paste ftw!), then used Sublime text editor to do a vertical edit, where I can paste the entire column of DL email addresses after -Identity right into the text file and then paste the whole column of owners after -ManagedBy and save as a .ps1 file, and run it. 

Set-DistributionGroup -Identity DL1@domain.org -ManagedBy owner1@domain.org,owner2@domain.org
Set-DistributionGroup -Identity DL2@domain.org -ManagedBy owner1@domain.org,owner2@domain.org,owner3@domain.org
Set-DistributionGroup -Identity DL3@domain.org -ManagedBy owner4@domain.org,owner5@domain.org,owner6@domain.org,owner7@domain.org

It shouldn't have been this difficult or ugly, but it's what I had to do to set the damn owner field to multiple values. Anyway, it is done, and I have about a week of relatively chill time before I have to migrate an organization we merged with into our Microsoft tenant...so another email migration. About 100 users, so should not be nearly as bad, hopefully. 

Monday, November 8, 2021

Sometimes you get throttled...

I've been working on a way to convert most of our M365 groups into DLs/Distribution Lists. And that's not super straight forward because it's not something people have to do often. But we had a bit of a miscommunication during the migration about what the requirements were, so now I have to correct it by converting M365 groups back to DLs. I have to first export all 2500+ M365 groups from our tenant, make sure I capture the current owners, members, names, and email addresses (creating a monster CSV file with over 25,000 lines). Then I have to exclude the groups that already have data in SharePoint or are using Teams (since these functions are not available to DLs). Part of the reason for the conversion to DLs is that in the old GSuite environment, these groups had external members and also nested groups. M365 groups can do neither of these things, so I also have to capture all the external users and nested groups from the old GSuite environment so I can add them to the DLs once they have been created. 

I finally have to delete the M365 groups, create the DLs, and add the members and owners. I also have to create mailContacts for any external users (a pre-requisite before you can add them to any DLs). Then I have to do a final pass where I add the external users and nested groups(that should now be DLs). 


I opted to break down our massive group and member list (around 25,000 lines) into 10 batches, to keep it a tad more manageable. I've been running batches since around 9am. It's 4 pm and only 4 batches have finished...So I decided to run 3 PowerShell windows so I could run multiple batches at a time and finish this today......and I got hit with a throttle warning by Microsoft...


So hopefully I didn't make things slower by running more than 1 at a time. I'll be babying this the rest of the afternoon just to make sure it doesn't error out or crash on me...

Wednesday, November 3, 2021

Sometimes you play futsal...

 I started playing Futsal some years ago. It's basically indoor soccer, 5v5, with a keeper/portero and some slightly different rules to adapt to the smaller space. 

The courts I play in. Looking over from upstairs while I wait for our court to open up. 

The ball is slightly smaller (like a size 4 ball more or less), but it is heavier, and bounces way less than a standard soccer ball. 


I usually only play once a week, very seldom I'll play twice a week in a league here. Anyway, this is all to say, I recently had to buy shoes because I kept getting blisters under my foot with my current shoes (I'll spare you the photos, they aren't pretty haha). They don't seem "worn out". I don't know what changed, but I got tired of the blisters and bought a different kind. 

Old shoes on the right

I decided to go with a more substantial shoe, with more of a sole and more cushion, while still being futsal shoes. I really liked how light the old shoes were and how thin everything on them was, but apparently my actual feet disagreed. I already used the new shoes a couple times and so far so good, no blisters. So either the old ones are worn out or lost what little cushion they had, or I'm just too old and need more cushion now haha. 

I enjoy playing quite a bit, so I hope to be able to keep playing for many years to come.