The other key thing is that Powershell has straight access to the whole .NET framework (or whatever its called these days) except you've gotta switch to .CallSomeMethod(with,brackets) syntax for that.
This list of common Gotchas on SO was useful to me: https://stackoverflow.com/a/69644807/22194
Powershell is quite good at working with CSV: Import-CSV, Export-CSV, Where-Object, Select-Object, Sort-Object, Group-Object etc become quite handy when used together.
Do-Something withthisfile.txt -AdditionalParam 23
But if you're calling a .NET method you switch to C# syntax with brackets and commas:
$str.Trim('-')
I mean thats kindof obvious but its one of the many things that makes Powershell's learning curve a little steeper. But hey we can always just google it which is par for the course anyway nowadays
That is, while you can call .NET methods on objects like:
$Object.SomeMethod('arguments')
You can also do:
[Namespace.ClassName]::SomeMethod('arguments')
And your Powershell scripts can even save you a lot of typing with the ```using``` function of Powershell to load namespaces: https://learn.microsoft.com/en-us/powershell/module/microsof...
Edit: As to why you would want to do this, usually it's because you want to do some scripting but you need to pull data out of some .NET application or out of Windows and there isn't a fully fleshed out cmdlet built for it. In a pinch, you can usually just use reflection to get it. For example, I needed to pull data from a Shared Outlook calendar that not everyone had access to and then do some date-math to share a time-sensitive schedule with a team living in quite a few timezones. Reflection to load the necessary Outlook and MSExchange elements, then the rest in Powershell. Now I have a script that is easy to pass around, can do this if I'm unavailable, and we can easily add/remove time zones/persons, and it just needed 5-ish lines of .NET inside of the Powershell script.
- Powershell isn't case sensitive. Typing `ConvertTo-Json` is annoying, but you can write `convertto-json` instead.
- `alias` tells you all the built-in aliases.
- The autocomplete is really, really good. Press ctrl-space to get all the options to tab complete commands, flags, or flag values. IE you can pipe something to `select -prop` and autocomplete all the fields of the thing. Also you can autocomplete with wildcards, like `*Json`.
- Flags don't need to be written out in full, you can write `select -exp` instead of `select -ExpandProperty`.
- Pipe stuff to `Out-Gridview` to get a filterable, sortable popup!
In terms of philosophy, think "Powershell but actually intuitive" : Every data is structured but command names are what you expect them to be. I usually don't even need to look at the documentation.
I liked it so much that I also replaced my shell on Linux with it, so I have the same terminal experience across all OSes
Powershell shines best when you're automating _Windows things_ or anything .NET adjacent. If you play inside the very specific rules Powershell allows, it works great and your Windows experience will likely be nicer.
So if you find yourself working on Windows and saying to yourself "wow, this works great but I wish I didn't have to babysit it like this", PS is your friend.
If you need to automate Active Directory, Exchange, MSSQL (I guess some general maintenance things or quick queries without SQL Management Studio), etc, PS is your friend.
Anything else, and you basically need to figure out how to get around the restrictions Microsoft put in to prevent you from doing this, usually using .NET code in your PS script.
e.g. https://dbatools.io/commands/ https://github.com/microsoft/ReportingServicesTools https://learn.microsoft.com/en-us/rest/api/power-bi/
Also all the normal Active Directory and file system tools, but those are too broad to go into.
and dotnet core, is just dotnet
i think they dropped the core part from the name as of dotnet 5
If you learn .net stuff it might make it more easy to use. You can access .net functions from powershell, so had you written that code in c# instead if node, you could reuse it in powershell anytime you want.
Although, personally I use shells to test stuff or for basic things, python kicks butt regardless of platform.
I hope your work let's you use wsl. If not, try running powershell.exe -version 1, that let's you bypass constrained language mode if that is the issue. Also, lookup set-executionpolicy and unblock-file, in case those are what you needed for the not allowed part. You can even bring your own powershell entirely! Powershell itself is an interface around System.Management.Automation windows/.net assembly. There are tools used in red-teaming where you just bring your own powershell interface and bypass any restriction. Even if you can't bring new exe's, no problem, you can relectively load assembly's and run them in memory, with or without powershell. Your org must be setup Crazy good if you have windows and there is no way to do whatever you want in powershell without admin rights. But don't get in trouble because of my advice!
Are you allowed to install Cygwin? It does a lot for making Windows a civilized environment.
I started to learn PowerShell and probably will still have to proceed, but I so far successfully avoided it in my current job. MSYS2 for sometime was a relief (WSL was a bit crippled on my company's internal network)
Also, you guys can probably install GitBash and claim it just came with Git...
powershell is good for controlling the windows operating system and doing basic things with objects. sysadmins are more likely to have a decent time with it than developers. Although, you can use it to interpret dotnet which is kinda neat.
$myJson = Get-Content .\test.json -Raw | ConvertFrom-Json
$myJson.Accounts.Users.asmith.department = "Senior Leadership"
$myJson | ConvertTo-Json -Depth 4 | Out-File .\test.json
from: https://techcommunity.microsoft.com/t5/core-infrastructure-a...Read powershell in a month https://www.amazon.com/Learn-Windows-PowerShell-Month-Lunche...
Microsoft had a good course for it, idk if this is good Youtobe has too https://learn.microsoft.com/en-us/training/modules/introduct...
I like powershell but I also dont use python or bash or whatever
My solution was to stop using it and instead use dotnet-script
https://github.com/dotnet-script/dotnet-script
Scripting with the full power of modern C# has been a huge win for me. And same/similar scripts will work on Windows/Linux/Mac. As my work language is C#, I don't have to context switch to another language for scripting.