5 ms·
On that note if you are a .NET developer you owe yourself to learn PS and how to write cmdlets, it's such a powerful and easy way to expose a CLI for your .NET
by rubber_duck 10y ago
On that note if you are a .NET developer you owe yourself to learn PS and how to write cmdlets, it's such a powerful and easy way to expose a CLI for your .NET app compared to stdio and command line arguments parsing - it's incredibly powerful and trivial to do.
Unfortunately most .NET devs are programmers who grew up with VB, RAD and GUI tools they don't understand the value of exposing UNIX like small functionality CLI commands over big monolithic services, GUI apps, etc.
- chadgeidel 10y agoI've been dabbling with PS (using it as my primary console) but my workflow just isn't that complex, so I don't have a compelling reason to write cmdlets (yet!). Can you recommend a good tutorial?
- rubber_duck 10y agoI've used MSDN docs but I wouldn't call that a tutorial :)
- Sacho 10y agoThe msdn docs are great, it's just difficult to navigate them. Perhaps this would help? https://msdn.microsoft.com/en-us/library/dd878294(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/dd878294(v=vs.85).a... There's tutorials in there as well, but I didn't find them very useful compared to the overview/concepts documentation.
- rubber_duck 10y agoYeah that's what I went trough as well but usually tutorials are shorter and more to the point, this is more reference/in-depth style - I'm guessing OP was looking for something along those lines.
- flukus 10y agoI'm a .net developer, I still install cygwin/bash on my computer because I can write stuff quicker and better. PS get's incredibly verbose for anything non trivial. I learned powershell long before bash too.
- will_hughes 10y agoCalling Powershell incredibly verbose is about the same as calling C# incredibly verbose. Sure, perhaps they're not as compact as some of the incredibly information-dense perl scripts that people come up with. I'd wager though that it's easier to understand what a random powershell script is doing than a random perl or bash script that pipes output throgh a dozen utilities.
- flukus 10y agoI've got an example of powershell getting verbose here: http://flukus.github.io/2015/03/13/2015_03_13_Powershell-is-a-Joke/ http://flukus.github.io/2015/03/13/2015_03_13_Powershell-is-... . Ignore the rest and look at the example where I'm trying to copy a directory recursively and with a filter. In bash the same task is a relatively simple one liner: find . -type f -name '*.html' -exec cp {} /home/new_dir/{} \; If you know a simpler way in powershell please post it though.
- will_hughes 10y agoWell yes, that's an example that's relying on the find utility, for which the equivalent in the windows world (at least for file management) is robocopy. robocopy /r $pathFrom $pathTo *.html If you wanted to exclude say 'main.js' then it'd be: robocopy /r $pathFrom $pathTo *.html /xf main.js ..and /xd is for excluding directories too. I guess copy-item should be smarter to be able to handle this. Also, for what it's worth, your example in the linked post is a bit more verbose than it really needs to be. You're comparing a full-up programming language to nant there. So yeah, it's a bit more verbose there. But I bet I can come up with a counter-example where nant is a giant nightmare to get right (or requires just dropping straight to executing external commands) (There's a reason I've killed off all usage of nant years ago, and gone to powershell for build scripts)
- tracker1 10y agoI learned C# with a big fat book, and the command line compiler... I understand the usefulness of command line applications. However, when I need more than what a simple shell script gives me, I'm more inclined to reach for node, ruby or python than C#/.Net ... the overhead for a quick scripting environment is quite a bit lower than having to setup a project and build requirements. I've done both... Why node, is simply npm... create a directory, npm init, write my script, etc. reference it from an alias or .cmd in my ~/bin directory (added to my path). Then it works in windows, mac and linux which I use all regularly. PS is mostly windows.
- rubber_duck 10y agoHave you ever written a commandlet ? This is my point, regardless of how you feel in PS vs Bash or Python vs C# - exposing your application logic trough commandlets is incredibly simple and powerful - much simpler than doing a CLI app in other languages even with argument parsing frameworks in python and likes, commandlets let you pipe and return/accept .NET objects. So my comment isn't PS everything or C# everything, it's if you're using C# to write a big fat monolithic app that has multiple isolated functionalities you can expose those fairly easily with PS.