Ludovic Frank - Freelance developer

Powershell and Linux, a little feedback

ionicons-v5-k Ludovic Frank Sep 9, 2024
83 reads Level: Confirmed

Hello, hello 🙂.

Thanks for clicking on this article 😁, for the record, it will be less condensed than the last one, this week, we're going softer 😛.

Basically, I'm not familiar with Powershell, I'm more in the world of penguins and all that... but a few months ago, I had to work with Powershell ... and Linux.

Today, I'd like to tell you a little about my experience of this adventure, take this article as a little story from a guy who didn't know Powershell, but had to get to grips with it 🙂.

Microsoft 365 is ubiquitous in the enterprise

And yes, it's a fact, you can't miss it, most of my customers are on Microsoft 365. As a result, it's hard to miss out.

Powershell, or how to communicate with Microsoft 365

With Powershell, you can do all sorts of things on your Microsoft 365 account, such as link a user to a group, add a user, delete a user, etc. In short, you get the idea.
In short, you get the idea.

When the need goes further

Let's talk about the project I was working on.

The idea was simple: a Symfony project running on a Linux server needed to be able to communicate with Microsoft 365.

The customer had already had a Powershell script developed by someone whose job it was, and his script was impeccable, but there was a problem...

The script was written for Powershell 6, but under Linux, only Powershell 7 (Core) is available.

How do you rewrite a Powershell 6 script to Powershell 7 without Powershell skills?

(Maybe I'm saying "Powershell" a bit too much in the title of this section, don't you think?)

So I had no choice but to rework the script so that it would work under Powershell 7.

To do this, I took the script, the Microsoft documentation and the artificial intelligence - no choice. As I set to work, I started to see which functions no longer existed under Powershell 7, and to find replacements, I used ChatGPT at first, the problem being that ChatGPT sometimes made errors, so I went step by step.

One of the most confusing things is that on Powershell 7, the "Get-Azure*" functions no longer exist, so I had to use functions starting with "get-MG*". I also remember that the whole "authentication" part, well yes, to communicate with 365, you have to authenticate first, which was a bit restrictive.

Dockerizing all that? yes, but not on a Mac with Apple Silicon

At the time, I still had my 2017 27-inch iMac as my main computer, so creating the Docker image wasn't very complicated.

You create an image with the Symfony project, install Powershell and Symfony can run "pwsh".

In short, nothing insurmountable.

Later, I had to come back to this project, but now I have a Mac with Apple Silicon, and the server on which this project runs is obviously an Intel processor.

So I add "--platform linux/amd64" to my Docker command, except...

Crash when creating a Docker image with powershell

Here's what happens, I imagine that Docker uses Rosetta 2 for the task, but it crashes at that point.

I didn't bother, I went back to my 2017 27-inch iMac to redo the Docker image.

And now the project is running?

We've briefly gone over it 2-3 times since, but it's been working for months: Symfony + Docker + Powershell.

Conclusion

As I said, it was a quiet article this week.
Just a little feedback on an experience I had a few months ago.
Having said that, Powershell on Linux works just fine 🙂.

Have a great week 😁.