r/PowerShell • u/Imaginary_Rip2833 • 23d ago
Information I am leaving MS Graph (Why beginners should start with core PowerShell)
I've realized that learning MS Graph as a beginner is like trying to learn algebra before you know basic addition and subtraction.
A few weeks ago, I came to this community asking if I had made the right move by starting with Graph. I now have the answer for anyone who might be asking the same question.
No, it is not a good idea.
The Graph API will give you a massive headache. It forces you to wrestle with complex nested objects, OAuth permissions, and weird API limits before you even truly understand how a foreach loop or a pipeline works. You have to understand the basics of the language before you start digging into massive, complex modules like Graph.
I am stepping back to master core PowerShell first. Has anyone else here taken this route?
Trust me, i have learnt a lot I believe while learning with MS Graph but its too much to handle😃
37
u/muddermanden 23d ago edited 23d ago
You can use F12 and copy Graph API URI from network tab while navigating or performing actions in the portals in the browser. Then use the Find-MgGraphCommand -Uri <paste URI here>
It helps you discover commands and their associated permissions.
PowerShell module is just wrapping the API.
However, when a command is not generated for PowerShell Microsoft.Graph module (when API is ahead), you can use Invoke-MgGraphRequest -Method <GET|PATCH|POST|DELETE> -Uri <Paste your URI here>, to act as the low-level interface to Microsoft Graph REST API.
5
u/LookAtMeInMyEyeball 23d ago
That's how you learn.
Also, the only Graph module that matters is Microsoft.Graph.Authentication, paired with some Az modules, you can do everything you need through
Invoke-MgRestMethod- I see the whole Microsoft.Graph module as a crutch with too many breaking changes. Don't bother with them.3
u/Kemeros 22d ago
You won't learn unless you have something to accomplish.
Learn what you need to accomplish your goal safely.
Also spend some time understanding object types. Otherwise some commands will fail because you are feeding them the wrong typed object. This is the most important thing. Everything else falls into place after that.
2
u/_RemyLeBeau_ 23d ago
Sometimes, you need to pivot. Knowing when to do so, shows maturity.Â
2
u/lurkelton 21d ago
Personally, I use this more 'Graph Explorer-style' function directly from PowerShell. It handles OData query formatting, pagination, and a few other things for you.
Examples:
Might be worth checking out if you want to experiment with Graph without getting bogged down in URL formatting and pagination etc.
Disclaimer: I'm the author of the tool.
22
u/Modify- 23d ago edited 23d ago
My path was organic, like "this is tedious, maybe I can automate this"
When I discovered I could with Powershell, I started to do more and more with it.
In the beginning it was mostly writing oneliners to do simple stuff.
Then little scripts with the help of the internet (pre chatgpt).
Eventually when I wanted to go to the next level I decided to watch the CBT nuggets course.
This helped me a lot. So I took on harder tasks etc.
Current day, I have build a lot of tools (functions/modules) which can help me do things faster.
I'm now the go to Powershell guy in our company.
23
u/Low-Branch1423 23d ago
Yeah unless you are already an app dev, straight to any API is a bad move.
Normal powershells biggest advantage is its ability to make a variable type and depth based upon what you are doing.
A standard get-aduser or CSV import and loop would be a much more beginner friendly task.
9
u/rickAUS 23d ago
If you were hitting the API endpoints using REST operations I'd understand your position better, at least with the complex nested objects stuff. But since it seems like you're using the PowerShell module I'm having difficulty understanding your problem with Graph. The Cmdlets within it are not significantly different to any other module and the Graph API doco is extremely clear on the permissions each endpoint requires.
I'll admit I had some issues getting into Graph, but that was because I was deliberately using REST to hit the API endpoints rather than using pre-made connectors in Power Automate because the function was to ensure it worked via our enterprise app, and most of the connectors required user auth instead.
Otherwise there's nothing preventing you from learning Graph alongside the fundamentals of PowerShell since it's like any other module you'd use.
4
u/maxfischa 23d ago
You ALWAYS start your journey with the book „powershell in a month of lunches“. After that i would say its ok to dive into more specific fields. Graph i would also only recommend after working with the GUI portals for a while. Once you step into the whole API permissions ignoring RBAC restrictions and go down the rabbithole the lines get VERY blurry for beginners.
1
u/rswwalker 23d ago
There is no shame in using Microsoft.Graph PS module. All the API quirks are handled for you and you only need to Invoke-RestMethod or Invoke-Web for rare edge cases, in which case you can ask AI to give you a code sample.
1
u/cjcox4 23d ago
Graph is more "lasting". That is, MsGraph api, even the ridiculous "forever beta" api, has been around for a long time. Just my own general observation. The experience of "the many years" vs. "new, shiny". So, sure, if your world is platform specific and you don't mind using things that might not have full coverage (where you're back to using graph api) and might change a bit over time... up to you.
1
u/BlackV 22d ago
Keep going
Keep learning the basics (loops/if/switch/etc)
Keep using g graph, but if it's too painful feel free to to use the other graph modules instead, it makes more dependcies but is a more familiar verb noin syntax
Additionally there are the entra cmdlets which are more human generated to bridge the gaps between machines and man when using graph
1
u/AmitBrian 22d ago
Keep in mind, there are 3 ways of using MS graph. The first is the very hardest. No Windows PowerShell at all using a completely different language with REST API. Don’t even bother. The second is with Invoke-MgGraphRequest (newer version of Invoke-WebRequest) that will allow you to use the token from Connect-MyGraph to get the token for Graph already in PowerShell and makes things so much easier and lets you do things like PowerShell.
The thing to remember is that, ESP in Microsoft 365 Microsoft is moving more and more away from traditional modules and into more Graph based cmdlets.
2
u/Fallingdamage 22d ago
I've been in powershell far longer than the graph API existed. When web requests were still an exotic practice. I dont know what I would be doing with it if it wasnt for all the cumulative knowledge built up before that. For most of my scripts, Graph is just a source of information or for simple POST instructions for various tooling.
Yeah, taking massive datasets out of our graph and knowing how to work with them is 99% of the work. If you only know graph, you're just copying/pasting while hoping for the best like a script kiddie.
1
u/Proxiconn 23d ago
I just use the c# wrapper and it makes the headaches go away.
Same is true for the msgraph wrappers ms provides for powershell.
I used to like hand rolling custom function/ API wrappers for everything but msgraph is definitely not one of them.
1
u/MalletNGrease 23d ago
Graph is a hog. Look at the wrapper modules like Microsoft Entra PowerShell since they're intended for humans.
1
u/netmc 22d ago
My first foray into powershell was creating a PS2 compatible script to install PS5.1. This required unzipping a downloaded file from Microsoft. I couldn't get PS2 to unzip to work with a dynamic path and file. A hardcoded value worked, but using a variable did not. I ended up loading an assembly via a reflexive call and using comspec to force a subshell to load .net4 under PS2 and I was able to use the dot net 4 unzip function and use that. This took me weeks to investigate and get working. This was definitely like jumping into the deep end to try and learn how to swim.
1
u/ApprehensiveVisual97 22d ago
Why is anyone coding in pwsh? All mine is either codex or GitHub for copilot. Better and faster that I can type
1
u/BlueLining-Solutions 21d ago
Graph is a little bit of a headache to actually install combined with if you can get the communications right per instance has almost its own permission as well. Love my powershell
1
u/nkasco 20d ago
Delegated permission scenarios with the MS Graph PowerShell SDK loop authentication anyway. Most people just use Invoke-MgGraphRequest and let it handle the auth token retrieval for application permissions. Beyond that, it's pretty lacking and generated via autorest.
1
u/YT-Deliveries 18d ago
Graph via Powershell for Intune management is very useful
1
u/Entegy 18d ago
I think a lot of people need to realize that Graph isn't a PowerShell thing. It's not designed for PowerShell. It's a REST API.
Most sysadmins don't deal with REST. This is typically a business integration/dev thing. I was lucky to be involved in a project that gave me exposure to REST APIs to pull and push data with JSON files - automated with PowerShell and Invoke-RestMethod.
Getting the fundamentals of PowerShell is always a good thing. It's not going to help much with Graph.
Now, this doesn't excuse the state of Graph PowerShell modules. These half-assed AI generated modules are really there to just help ease the transition from Windows-only, PowerShell-first DLLs to Graph's REST APIs that can be run by anywhere or anyone. But when anything even slightly off the beaten path is a cmdlet that just takes a JSON-style hash table with all your changes passed to a single parameter called Body, you wonder why you're even running a cmdlet in the first place.
For me I at least find it easier to use Connect-MgGraph and then Invoke-MgGraph than obtaining an auth token and using Invoke-RestMethod.