A couple of things to consider. Specifically to your issue, you may want to consider looking into the #Requires keyword. It should make fixing versions of modules easier and I'd recommend it...
A couple of things to consider. Specifically to your issue, you may want to consider looking into the #Requires keyword. It should make fixing versions of modules easier and I'd recommend it particularly if you're consuming the Az modules (although to your point, it's a web of dozens of interconnected modules and it might take a couple hours to figure out which versions of what module you need to fix).
Alternatively, if you're used to bash, you're probably pretty familiar with curl. Most, if not all, of the use cases you're describing have REST endpoints you can integrate with using Invoke-RestMethod:
It has the added benefit of returning the calls in object format which, fan of pwsh or not, is way easier to work with than what curl returns.
Chances are those PSModules you're leveraging are just using the REST endpoints behind the scenes (many of the modules are auto-generated based on the REST endpoints), so leveraging them directly will both give you more control over the information returned and allow you to fix the backend REST endpoint in your code so you don't run into those version bump issues you're seeing now.
Edit: Additionally, you could also look into PSDepend. It's been around for a while and can help manage dependencies (once you figure out what you need exactly). If you're distributing this to the rest of your team, it'd be a handy tool to get their environment configured properly. Also added a few useful doc links.
One of the primary reasons why I'm not a fan of PowerShell is that even though I like some of the ideas, I just don't see the point of learning it if I don't have to. I can understand that...
One of the primary reasons why I'm not a fan of PowerShell is that even though I like some of the ideas, I just don't see the point of learning it if I don't have to. I can understand that Microsoft really needed to go beyond their DOS batch scripting limitations (for decades before PowerShell came out, even), but I legitimately think they would have done better to just have an official pre-bundled ports of bash/zsh and some of the GNU utilities. That's one of the major reasons why devs tend to love Macs; it all works without having to have a virtualized linux instance like WSL2. Sometimes I wonder how much of Microsoft's decision making comes from not invented here syndrome.
That's the way Microsoft does things, 12 ways to do the same thing, 11 of them deprecated. I ran into a similar issue with msonline the other day when I needed to change an attribute in Azure and...
That's the way Microsoft does things, 12 ways to do the same thing, 11 of them deprecated. I ran into a similar issue with msonline the other day when I needed to change an attribute in Azure and couldn't find anything documented, but there were 100's of old threads about how to do it using the old msonline method.
Well it's still being developed, and I don't think it solves most of your problems, nushell might be worth looking into. And from the people I know who are better at this than me, I believe dotnet...
Well it's still being developed, and I don't think it solves most of your problems, nushell might be worth looking into.
And from the people I know who are better at this than me, I believe dotnet 8 is coming with some improvement to authentication, which might wind up affecting other systems like powershell/graph (i'm a little unsure on the details because I mostly code in C#/F# and make apps so coming from a different perspective).
I've specifically avoided putting myself in a position to do so, for pretty much all the reasons you listed. But if I were gonna be tasked with doing so tomorrow, I'd give a good look at Ansible's...
I've specifically avoided putting myself in a position to do so, for pretty much all the reasons you listed.
But if I were gonna be tasked with doing so tomorrow, I'd give a good look at Ansible's Windows modules. Probably still have to use Powershell, depending on the tasks needed, but perhaps using Ansible as the glue may help smooth over some of those problems.
I don't have an answer for you since I don't work with Windows at all, but it does always surprise me to see people love on Powershell. We have people here who are absolutely passionate about it....
I don't have an answer for you since I don't work with Windows at all, but it does always surprise me to see people love on Powershell. We have people here who are absolutely passionate about it. I just didn't expect that from a Microsoft CLI tool.
PowerShell is very powerful when it comes to managing Windows and anywhere else it has modules (AWS is another one where I use PowerShell frequently instead of the AWS CLI). A lot of that comes...
PowerShell is very powerful when it comes to managing Windows and anywhere else it has modules (AWS is another one where I use PowerShell frequently instead of the AWS CLI).
A lot of that comes down to the fact that it's not just text in PowerShell, it uses objects and most things in it are objects which makes item easier to work with and completely removes the need to use things like awk to return a specific column out of returned text (as a simple example). Outside of objects, PowerShell has built in functions to manipulate text and perform math equations without needing to rely on additional tools.
It's also very helpful for managing Active Directory - any AD Admins not using PowerShell to manage it are not really up for the task of managing it - it's easy to update 100s of user, computer or group objects that would take hours to do manually.
OP's frustration with the Graph and MSOnline modules are 100% valid though - Microsoft is not documenting those well enough at all let alone including examples, and along with the Teams module they're frequently being updating without correponding documentation. It's generally a bad idea to update those modules without testing on a non-prod system first.
OP feels PowerShell 'doesn't make sense' compared to Bash since that's what they're more familiar and experienced with; I wish Bash was more like PowerShell when I'm managing Linux systems since I'm more comfortable with it than I am with Bash. (PowerShell can be installed on Linux but I'm certainly not about to install it on production servers).
Yeah, I had to rebuild the new user script for my company, from the previous one using so many poor practices (like instead of defining functions, they just repeated code for several things many...
Yeah, I had to rebuild the new user script for my company, from the previous one using so many poor practices (like instead of defining functions, they just repeated code for several things many times over).
The new version has been running solidly for over a year now without any changes.
I'm still learning Bash - switched out my personal computer to OpenSUSE to avoid Windows 11. Just figuring out Bash arrays this morning. That's great to hear about text manipulation and math being built in, I haven't seen that yet but it's great!
My assumption is because it's a shell that actually goes beyond the "everything is a text stream" model of most unix shells*. Being able to have actual structured objects in my shell scripts makes...
My assumption is because it's a shell that actually goes beyond the "everything is a text stream" model of most unix shells*. Being able to have actual structured objects in my shell scripts makes things so much easier. Pair that up with the fact that I can import (or write!) modules written in C# and it feels like there's a much smaller gap between the power of writing a full program for a task vs writing a shell script.
*Nushell is out there, but it baffles me that every article or blogpost I see about it completely ignores the fully-in-use Powershell when talking about "reinventing the shell"
Personally, I really like PowerShell. I like it enough that it is my default shell for MacOS and Linux (WSL) installs as well. There are some modules which are Windows only, and that can be...
Personally, I really like PowerShell. I like it enough that it is my default shell for MacOS and Linux (WSL) installs as well. There are some modules which are Windows only, and that can be frustrating at times, but the core language is something I can use across different Operating Systems and I can share my $PROFILE. That's very useful for a lot of situations. I have additional scripts I use to encapsulate specific environment needs, but most of setting up my system can be used independent of the platform.
A couple of things to consider. Specifically to your issue, you may want to consider looking into the #Requires keyword. It should make fixing versions of modules easier and I'd recommend it particularly if you're consuming the Az modules (although to your point, it's a web of dozens of interconnected modules and it might take a couple hours to figure out which versions of what module you need to fix).
Alternatively, if you're used to bash, you're probably pretty familiar with curl. Most, if not all, of the use cases you're describing have REST endpoints you can integrate with using Invoke-RestMethod:
It has the added benefit of returning the calls in object format which, fan of pwsh or not, is way easier to work with than what curl returns.
Chances are those PSModules you're leveraging are just using the REST endpoints behind the scenes (many of the modules are auto-generated based on the REST endpoints), so leveraging them directly will both give you more control over the information returned and allow you to fix the backend REST endpoint in your code so you don't run into those version bump issues you're seeing now.
Edit: Additionally, you could also look into PSDepend. It's been around for a while and can help manage dependencies (once you figure out what you need exactly). If you're distributing this to the rest of your team, it'd be a handy tool to get their environment configured properly. Also added a few useful doc links.
One of the primary reasons why I'm not a fan of PowerShell is that even though I like some of the ideas, I just don't see the point of learning it if I don't have to. I can understand that Microsoft really needed to go beyond their DOS batch scripting limitations (for decades before PowerShell came out, even), but I legitimately think they would have done better to just have an official pre-bundled ports of bash/zsh and some of the GNU utilities. That's one of the major reasons why devs tend to love Macs; it all works without having to have a virtualized linux instance like WSL2. Sometimes I wonder how much of Microsoft's decision making comes from not invented here syndrome.
Of course it was. Why embrace a decades-old favored tool and make it work well rather than push your fledgling tech stack (dotnet) harder?
That's the way Microsoft does things, 12 ways to do the same thing, 11 of them deprecated. I ran into a similar issue with msonline the other day when I needed to change an attribute in Azure and couldn't find anything documented, but there were 100's of old threads about how to do it using the old msonline method.
Why not use bash scripts on Windows subsytem?
Well it's still being developed, and I don't think it solves most of your problems, nushell might be worth looking into.
And from the people I know who are better at this than me, I believe dotnet 8 is coming with some improvement to authentication, which might wind up affecting other systems like powershell/graph (i'm a little unsure on the details because I mostly code in C#/F# and make apps so coming from a different perspective).
I've specifically avoided putting myself in a position to do so, for pretty much all the reasons you listed.
But if I were gonna be tasked with doing so tomorrow, I'd give a good look at Ansible's Windows modules. Probably still have to use Powershell, depending on the tasks needed, but perhaps using Ansible as the glue may help smooth over some of those problems.
I don't have an answer for you since I don't work with Windows at all, but it does always surprise me to see people love on Powershell. We have people here who are absolutely passionate about it. I just didn't expect that from a Microsoft CLI tool.
PowerShell is very powerful when it comes to managing Windows and anywhere else it has modules (AWS is another one where I use PowerShell frequently instead of the AWS CLI).
A lot of that comes down to the fact that it's not just text in PowerShell, it uses objects and most things in it are objects which makes item easier to work with and completely removes the need to use things like awk to return a specific column out of returned text (as a simple example). Outside of objects, PowerShell has built in functions to manipulate text and perform math equations without needing to rely on additional tools.
It's also very helpful for managing Active Directory - any AD Admins not using PowerShell to manage it are not really up for the task of managing it - it's easy to update 100s of user, computer or group objects that would take hours to do manually.
OP's frustration with the Graph and MSOnline modules are 100% valid though - Microsoft is not documenting those well enough at all let alone including examples, and along with the Teams module they're frequently being updating without correponding documentation. It's generally a bad idea to update those modules without testing on a non-prod system first.
OP feels PowerShell 'doesn't make sense' compared to Bash since that's what they're more familiar and experienced with; I wish Bash was more like PowerShell when I'm managing Linux systems since I'm more comfortable with it than I am with Bash. (PowerShell can be installed on Linux but I'm certainly not about to install it on production servers).
Yeah, I had to rebuild the new user script for my company, from the previous one using so many poor practices (like instead of defining functions, they just repeated code for several things many times over).
The new version has been running solidly for over a year now without any changes.
I'm still learning Bash - switched out my personal computer to OpenSUSE to avoid Windows 11. Just figuring out Bash arrays this morning. That's great to hear about text manipulation and math being built in, I haven't seen that yet but it's great!
My assumption is because it's a shell that actually goes beyond the "everything is a text stream" model of most unix shells*. Being able to have actual structured objects in my shell scripts makes things so much easier. Pair that up with the fact that I can import (or write!) modules written in C# and it feels like there's a much smaller gap between the power of writing a full program for a task vs writing a shell script.
*Nushell is out there, but it baffles me that every article or blogpost I see about it completely ignores the fully-in-use Powershell when talking about "reinventing the shell"
Personally, I really like PowerShell. I like it enough that it is my default shell for MacOS and Linux (WSL) installs as well. There are some modules which are Windows only, and that can be frustrating at times, but the core language is something I can use across different Operating Systems and I can share my $PROFILE. That's very useful for a lot of situations. I have additional scripts I use to encapsulate specific environment needs, but most of setting up my system can be used independent of the platform.