DEV Community

Cover image for PowerShell Tutorial (Especially for People Who Hate PowerShell)

PowerShell Tutorial (Especially for People Who Hate PowerShell)

Ryan Palo on April 29, 2018

Preface This is a long article. I'm putting a table of contents up here for the impatient, so you can find the specific section you're ...
Collapse
 
zeerorg profile image
Rishabh Gupta

I haven't learned PowerShell but I am pretty positive about what it wants to do, that is make scripting easier and more programming like. My greatest pain when working with linux is writing a bash script.
PowerShell is different from other shells on linux as it focuses more on verbosity and being script friendly than just being a shortcut to do stuff.

Collapse
 
zeerorg profile image
Rishabh Gupta

Also a great post !!

Collapse
 
rpalo profile image
Ryan Palo

Thanks! Glad you liked it!

Collapse
 
shalvah profile image
Shalvah

Or, you might simply stop telling people how much you hate PowerShell whenever they mention it.

I think I'll stick with this. I've gotten used to PowerShell, customized it to be somewhat like Zsh, but some things still annoy me. Like the fact that history is only saved for the current session by default. And the fact that right-clicking does a paste. And the fact that the shell handles windowing and line wrapping SO POORLY. And the fact that I have to confirm another prompt anytime I hit Ctrl-C. Oh, and the fact that the shell is SO DAMN UGLY no matter how much you customise it.

I get the whole C#-like thing, and I could even come to like it, but I don't understand the design decisions that led to the things above; for a team like Microsoft, it's really disappointing.

Collapse
 
rpalo profile image
Ryan Palo

Hey, that’s fair! And if you got to the last line, it means you read the whole article, so that’s good enough for me 😁 do check out hypertext and/or cmder though. They make things a little nicer. Thanks for reading!

Collapse
 
shalvah profile image
Shalvah • Edited

Lol. Bad News: I skipped to the end. Good News: so I could find the "Bookmark" button

Thread Thread
 
shalvah profile image
Shalvah

So, two and a half years later, I finally finished this article!😄

I really love it. Well-written, very comprehensive and lots of useful tips. Plus a lot of the reactions you described were things I'd experienced too.

I'm in a different place now... In late 2018, I decided to learn PS, and I actually began to appreciate it. The host is still terrible, so I use Cmder (might consider the Windows Terminal when it's out).

Thanks for writing this.

Collapse
 
aglamadrid19 profile image
Alvaro Lamadrid

I find PowerShell very intuitive so far. The Object Oriented and Verb-Noun design has impacted positively my effectiveness at the time of Scripting (Windows Platform). And now with PowerShell Core, things will go to the next level I'm sure. Are you planning on writing about that (PS Core)? Thank you for the article Ryan.

Collapse
 
rpalo profile image
Ryan Palo

I hadn’t planned on it, but I’ll look into it, thanks!

Collapse
 
kennethrow profile image
Ken Row

Beware that Powershell's new-item will clobber a pre-existing file, whereas Bash's touch will just update its modification time. If you want a PowerShell touch to really behave like Bash, it'll require a function, not an alias.

Collapse
 
ltvan profile image
Van Ly

I think that you should include this in your post for completeness:

stackoverflow.com/questions/826465...

Collapse
 
ertant profile image
Ertan Tike

Post is great. It's help me to understand that i miss a lot.

But.

I still hate power shell. Why? Because power shell is one of 2005-era MS fallacy. (Like Win-FS, Metro UI among other etc) They take something does not work very well and re-design from scratch to sail to new seas.

Idea behind shell is you have some of "executables" to do some things. You call these executables from shell or you can put in a script file or you can call they from other executables. Some of executables are preinstalled (like ls, cp, mv) and if you don't have that executables you can install them (like git, npm, etc).

Power shell "cmdlets" are not executables, they are some registered commands which you do don't know where they come from.

Lets say you want to set some firewall settings from shell. Try to find related "cmdlet" if you can.

Lets say you found the "cmdlet" and if is not registered or if it's not compatible with your OS good luck with that.

Lets say you can run "cmdlet" and if you do not know object model of firewall library, go read some msdn pages and return back.

This is a part of "cmdlets" of firewall;

Copy-NetFirewallRule
Disable-NetFirewallRule
Enable-NetFirewallRule
New-NetFirewallRule
Remove-NetFirewallRule
Rename-NetFirewallRule
Show-NetFirewallRule

now compare this with how git or docker commands work. ( Wait... "Disable-NetFirewallRule" and "Enable-NetFirewallRule" ? why my friend??.. why?... )

I understand power shell is written with good intensions and super idealistic ideas to put some standard but I think power shell is not written to replace daily shell work, it's written to execute some (written in tears) script files and automate something.

Worst thing is; if I have to automate something, I could prefer to write in C# with IDE support (auto complete, debugging, refactoring etc etc) not in power shell. Because they are sailing in same sea.

Maybe I get older and wrong, I don't know.

Collapse
 
itsjzt profile image
Saurabh Sharma • Edited
Collapse
 
supermario_ai profile image
SuperMario

❤💯

Collapse
 
negibirendar profile image
Biren

if i am working with remote deployment and i need to pass local variable to remote machine, how i can

Collapse
 
rpalo profile image
Ryan Palo

I found this article after a quick search. For PowerShell 3, but seems like it might work. What do you think?