11 ms·
Ask HN: How to effectively learn PowerShell?
I've been looking around for a while now, but haven't really found what I'm looking for. Essentially, what I'd like to use to learn powershell effectively with is a "powershell by example" page somewhere, similar to gobyexample.com or rustbyexample.com where the tutorial encourages active tinkering.
What have you been using to effectively learn the ins and outs of powershell usage?
- _qc3o 10y agohttps://smile.amazon.com/Windows-PowerShell-Cookbook-Scripting-Microsofts/dp/1449320686/ref=sr_1_1?ie=UTF8&qid=1484500841&sr=8-1&keywords=powershell+cookbook https://smile.amazon.com/Windows-PowerShell-Cookbook-Scripti...
- AlexB138 10y agodkarapetyan linked a good Cookbook. That's essentially what you're asking for. In addition to that, when I had to learn Powershell I found "Learn Powershell in a Month of Lunches" quite useful. At the time it was considered the go to book for PoSh, but that may have changed.
- ygra 10y agoI may be an outlier in this regard. I learned PowerShell by starting to golf in it. However, while I know the language quiet well, I'm completely useless at using it for administrative tasks, simply because I've never done that with it. I use PowerShell as my go-to scripting language, calculator, interactive .NET playground and a bunch of other things, but rarely for managing Windows servers. I can recommend the PowerShell cookbook too, though. I've been a technical reviewer of the 2nd edition and at least back then it was good :-)
- nikbackm 10y agoI've started reading this one and found it pretty good. As a beginner at least. https://www.manning.com/books/windows-powershell-in-action-third-edition https://www.manning.com/books/windows-powershell-in-action-t...
- oellegaard 10y agoProtip: You'll find two app on Windows called Powershell. One is just called Powershell and the other is called Powershell ISE. I mistakenly picked the regular one, to later find out that Powershell ISE is epic. It's like a combination of a terminal and some kind of IDE.
- nailer 10y agoISE is the best for learning but doesn't have good readline support (it's not quite a normal windows console). Once you're up to speed, grab ConEmu. It's the iTerm2 of the Windows world.
- oellegaard 10y agoAt least you have proper copy/paste in ISE :P
- toyonut 10y agoIt either has the full powershell console in a pane depending on your view settings or you can hit f8 to run highlighted text or the line your cursor is on.
- aytch 10y agoConEmu is pretty great (and WAY better than a standard console), but CMDer builds upon the ConEmu base and improves it, in my opinion: http://cmder.net/ http://cmder.net/
- nathanaldensr 10y agoThere is an excellent series of videos on PluralSight. I can't remember for sure who the instructor was, but I always recommend them to anyone learning PowerShell. I think it's this guy: https://www.pluralsight.com/courses/powershell-intro https://www.pluralsight.com/courses/powershell-intro
- dedhed 10y agoEven though this is titled as PowerShell for Mac and Linux, one of the presenters is Jeffrey Snover who invented PowerShell. He provides some great information about how the pipeline works and compares it to the pipe system in Unix. I found it very informative. https://www.pluralsight.com/courses/play-by-play-microsoft-open-source-powershell-linux-mac https://www.pluralsight.com/courses/play-by-play-microsoft-o...
- mindcrash 10y agoNot sure how much time you have, but if you do not have much I strongly recommend "Learn PowerShell In A Month Of Lunches" [1] Basically means that if you can spend about one hour every day on the text and exercises in the book you will be able to grasp PowerShell scripting in about a month. [1] https://www.manning.com/books/learn-windows-powershell-in-a-month-of-lunches-third-edition https://www.manning.com/books/learn-windows-powershell-in-a-...
- lwkl 10y agoThis book is book great and after you've read it I can recommend "The Powershell Scripting and Toolmaking Book"[1]. I just started reading it and teaches you how to write good tools with practical examples and business scenarios. My next step will be learning Pester and DSC. Also "Powershell in Action" by Manning is great to lookup things in detail. [1] https://leanpub.com/powershell-scripting-toolmaking https://leanpub.com/powershell-scripting-toolmaking
- dhruvtv 10y agoDefinitely recommend the Manning book "PowerShell in Action" by Bruce Payette. The second edition is on Amazon but looks like a third edition is coming out in the Spring and you can pick up the EAP. https://www.manning.com/books/windows-powershell-in-action-third-edition https://www.manning.com/books/windows-powershell-in-action-t...
- minhaz23 10y agoWhat's a practical way to learn it on a Macintosh? VM?
- mindcrash 10y agoWindows VM, or if you are a daredevil you could try and install PowerShell 6 (which will be crossplatform) on macOS from here: https://github.com/PowerShell/PowerShell https://github.com/PowerShell/PowerShell (do note its currently in alpha state)
- Scriptor 10y agohttps://learnxinyminutes.com/docs/powershell/ https://learnxinyminutes.com/docs/powershell/
- ZenoArrow 10y agoWhilst you might get some value in trying to learn in a structured way, I'd say you'll get much more out of it if you try to scratch your own itch. In other words, think of something you want to script, then try to learn how to do that in PowerShell. What I think you'll find if you try learning something as vast as PowerShell with a general approach is that, whilst you may pick up some decent general habits, you'll also find yourself learning a whole bunch you never use. Learning PowerShell is different from learning a conventional programming language as each use case you'll have will make use of different commands. It's like having a DSL for each use case. You'll use different commands for Active Directory management, for Azure management, for file processing, etc... As long as you know the basics you can pick up whatever is going to be most relevant for what you do.
- nailer 10y agoI also moved from bash (after nearly 2 decades!) to powershell. Here's my powershell profile, including instructions for setting up a new box and additional aliases for Unix commands: https://github.com/mikemaccana/powershell-profile/blob/master/Microsoft.PowerShell_profile.ps1 https://github.com/mikemaccana/powershell-profile/blob/maste... Short answer for 'How do I learn powershell?' is: * Learn 'select' * Learn 'where' Once you get those two, and get out of the scraping with sed/grep/awk mentality you now properly get powershell.
- mastax 10y agoThere seems to be a certificate request appended to line 46 I don't know if this information is sensitive, but you probably don't want it there either way.
- nailer 10y agoGood spot - CSR is only a public key so not sensitive - but removed.
- golf1052 10y agoI don't remember where I found it but I use this for touch https://gist.github.com/golf1052/39603656500adcaef3e8fd3d210d91b5 https://gist.github.com/golf1052/39603656500adcaef3e8fd3d210... It acts like Linux touch where if the file already exists it just updates the last modified date
- newman314 10y agoWhy do you choose not to install OpenSSH over chocolatey? I'm looking for a clean way to install OpenSSH on Windows.
- mastazi 10y agoLooking at the code (commented lines at the top), I thought parent was using Chocolatey as a OneGet provider? See https://github.com/chocolatey/chocolatey-oneget https://github.com/chocolatey/chocolatey-oneget
- jamesdftx 10y agoI'd recommend: - "Learn PowerShell in A Month Of Lunches" - reddit.com/r/powershell - the powershell podcast at powershell.org
- jamesdftx 10y agoI'd recommend: - "Learn PowerShell in A Month Of Lunches" - reddit.com/r/powershell - the powershell podcast at powershell.org
- majkinetor 10y agoEffectively, forget about desktop and cmd and only live in powershell. That is what I do - Posh is my operating system, it autostarts with Windows. In a several months you will be effective user, but to master it will still take years. In this regard, few tips: - Install apps via Chocolatey. If app is not there create a package and maintain it. AU framework makes it one time development event. See this report: https://gist.github.com/majkinetor/a700c70b8847b29ebb1c918d47ee4eb1 https://gist.github.com/majkinetor/a700c70b8847b29ebb1c918d4... - Your profile is very important. I use profile.d which can be reused easily on all your machines: https://github.com/majkinetor/powershell_profile.d https://github.com/majkinetor/powershell_profile.d - Use Powershell Gallery and modules in general. Make module or reusable component for everything. See my work here: https://github.com/majkinetor/posh https://github.com/majkinetor/posh - Make sure you use mandatory cli tools: cinst conemu less peco sysinternals everything copyq - Do not use junk GUI editors such as ISE. Visual Studio Code is way better if you have to. Sometimes is OK when debugging. I would suggest vim because speed is of great importance in shell world. - Follow reddit community and ask questions there rather then on SO which is full of achievement biatches. Redditors will help you for free for the joy of sharing the knowledge. - Use Github to store all your stuff. Also, in coorporation you can use NAS share to let anybody import stuff from there. - DO NOT LISTEN naysayers about aliases - use default alises all the time. They are cross-platform and well known and I can go into neurolinguistics of why is it better and easier for the brain but I don't want to do it here. People will certainly whine now but ignore them. DEFAULT (READ ONLY) ALIASES ARE THE BEST. Particularly, if you see somebody does foreach-object or where-object just kill him ASAP. - Do ALL windows config from Posh. If you don't know ask around. If you are devops dude, you can thank me later, especially when you learn DSC and apply all that knowledge there or with boxstarter. - If you happen to be locked in older posh use PSReadLine. Keep in mind that $host.Version -lt '3.0' is full of surprises and use latest version if possible. - Do not compromise with others in coorporation. Ask for script for everything. If sysadmin tells you that server is low on disk you ask for proof in the form of the command you can execute. Ask for invoke-sql when using databases. If you give admin a job to create a IIS site for your web app ask for a script. If you are a project manager, do not close tickets without a script. - If you monitor vendor excursions in your company infrastructure, ask for transcripipt of ALL operations they do. You will thank me later. Do not sign their work without it. I can recommend "Windows Powershell In Depth" https://www.manning.com/books/powershell-in-depth-second-edition https://www.manning.com/books/powershell-in-depth-second-edi... And if you don't enjoy PS almost every single moment you are doing something wrong. PS: I do not work for Microsoft :) I just think bash and friends are ridiculous in 2017 and honestly a little embarrassing. Do not do that - install Powershell on Linux and Mac if you have to and keep your sanity. PS2: Somebody will certainly say that ruby/python/whatever is great on linux side. Ignore them. Those are not shell languages (while great otherwise and valuable in your skillset - cinst ruby python etc. is among my mandatory stuff but lets keep perspective here). Good luck.
- knocte 10y agoI strongly recommend against learning Powershell, it has horrid syntax and is not crossplatform. It wants to be a pseudo C# but without being C#. And anyway you can use scriptcs nowadays to write scripts in C# (or even better: .fsx scripts, with F#, which is more succint, less verbose than C#).
- majkinetor 10y agoYou should really really inform yourself better.
- jodrellblank 10y agoI strongly recommend against believing people who say PS is not cross platform when it is available for macOS and Linux and is open source too.
- robert_tweed 10y agoInteresting. Does it actually work though, or does it tend to depend on Windows-specific assemblies to do any useful work? The main use-case I have for Powershell is remotely administering Exchange. If I could do that from OSX or Linux, then that would be useful enough for me to spend the time learning it.
- Arnavion 10y agoIt's based on .Net Core, so anything not in core PS has to be available there.
- NetStrikeForce 10y ago> The main use-case I have for Powershell is remotely administering Exchange. If I could do that from OSX or Linux, then that would be useful enough for me to spend the time learning it. I guess you can always do powershell remoting? Apparently it also works from Windows to Linux! https://github.com/PowerShell/PowerShell/blob/866b558771a20cca3daa47f300e830b31a24ee95/docs/new-features/remoting-over-ssh/README.md https://github.com/PowerShell/PowerShell/blob/866b558771a20c... (got pointed there from this Reddit post: https://www.reddit.com/r/PowerShell/comments/4ziw85/anyone_manage_to_get_enterpssession_or/ https://www.reddit.com/r/PowerShell/comments/4ziw85/anyone_m... )
- BeetleB 10y agoSorry to piggyback on this post: I have to use Windows at work, and do not know Powershell. Several times I've debated learning it, but never put in the effort. Now I use Xonsh (http://xon.sh/ http://xon.sh/). It is a Python shell - cross platform and similar semantics to bash, etc. I was never a power bash/zsh user (scripting in them is Hell). The nice thing with xonsh is that it is Python. If you want to customize your environment, have complex aliases - well, you just write Python code in your config file. Learning PowerShell for Windows is the ideal. But xonsh is a good intermediate solution for people who don't want to invest in going all the way. (To be honest, I'm seriously considering switching to xonsh for my Linux machine - currently I use zsh).
- YeGoblynQueenne 10y agoxonsh looks interesting. My first question would be along the lines of "do you get command completion and nice syntax highlighting in the shell?" but I see in your link that it does have those, so that's a great start. My other worry is that there's going to be some things it's hard to do _on windows_ for any shell that isn't created by microsoft. Which is not the fault of xonsh, or any other alternative shell, obviously- but which might make psh a better deal in some cases. Can't think of an example though, to be honest :)
- quanticle 10y agoxonsh might be fine for interactive use, but I'd hesitate to use it for serious scripting. The nice thing about PowerShell is that it's a .Net CLR language. So, this means that anything that's accessible to .Net (including COM bindings) is also accessible to PowerShell. This means that for example, you can script IIS configuration and setup with PowerShell. You can script things like importing certificates. You can stop and restart Windows services. I'd be surprised if xonsh exposed the same amount of the Windows API as PowerShell.
- chris_wot 10y agoWith a bit of pinvoke goodness you can load unmanaged dlls also.
- iamkarlson 10y agoHow have i learnt powershell: 1. Replace cmd to powershell everywhere 2. Make you routine tasks automated by ps 3. Connect to remote machines by powershell only .... PROFIT
- chrisper 10y agoSo how well does number 3 really work? Is the experience similar to Linux and Bash in the way that you can do everything in the console.
- iamkarlson 10y agoYes, ps is very advanced tool. Difficult to find information how to do certain things but when you found them you have jedi power
- vmarsy 10y agoI looked at the Microsoft Virtual academy videos [1], they cover a lot of basics but were usefeul, having the creator of powershell teach the course helped understand the philosophy behind it. When searching for tutorials online, "the scripting guy" was useful, but more importantly I make sure to search for powershell v5, v4, or v3 tutorials. - There are lots of "old" tutorials, but I think there were major changes between Powershell v1, v2, and v3, so I try to avoid those, especially regarding modules [1] https://mva.microsoft.com/en-us/training-courses/getting-started-with-powershell-3-0-jump-start-8276 https://mva.microsoft.com/en-us/training-courses/getting-sta...
- liso 10y agoI checked this thread out just to make sure someone posted this link. I have not found a better resource for learning PowerShell anywhere. It covers what makes PowerShell special, and then gives an excellent primer on the language. Start here.
- sixothree 10y agoMaybe it's just me but I find this series incredibly annoying to watch. I doubt I can tolerate 5 hours of these two. Each hour of video has 10 minutes of content.
- YeGoblynQueenne 10y agoI believe the best way to learn powershell is by using it as your shell, everyday, for real-world tasks, particularly in your job. Start small, with ls, cp and cat, and don't force the pace. psh is a shell first and foremost- a shell with a very nice language, but a shell all the same. So get comfortable using it as a shell. First thing is to create your $PROFILE. Google for an example and see if you can edit it to suit you. Then get chocolatey, PSCX (psh community extensions), posh-git and vim, and get used to doing most of your work on the command line (like you'd do with bash, on Linux). See what tasks you can automate by writing a few short scripts- very simple things at first, like copying and renaming files, setting up directory structures and so on, then progress to processing xml and setting up scheduled tasks, and sending email, setting up credentials etc. After a few months you'll find that you can wean yourself of windows GUIs for most of your everyday tasks and probably all of your not-so-everyday ones. psh being a command-line tool, it's far easier to learn it like that, than trying to learn the language first. You can learn the basics of the syntax allright, but there's a bazillion commandlets that you will never be able to remember, unless you use them in your everyday work, and incorporate in your scripts, and those commandlets are often integral to the use of psh. Basically, you can't separate the language from the use of the shell, so you shouldn't try. Learn them both at the same time. % % % Here's my personal example: I learned psh to avoid the long rdp queues in a past workplace. I guess that company didn't want to shell out for more windows server licenses and so there was a limit to the number of people who could rdp to a server at the same time- just two or three people per server. So there was always a bit of a queue and I often had to wait between a half hour and a couple of hours before I could get a slot. Or someone would go for lunch and forget to log out, and you had to kick them out and it was generally a big drag. At some point I started using psh as my windows shell, and then I found out about windows remoting [1], which sounded a lot like ssh on Linux- basically, it lets you open a shell on a remote computer. Next time I had a slot on a remote machine, I enabled remoting and suddendly I could do all the work I needed on the command line, while everyone else still had to wait in line for an RDP slot [2]. Needless to say, this made my life and my job a hell of a lot easier, not to say pleasant (I might have had a few smug smiles on my face, at times). I'll note there was only one thing I couldn't do remotely: running a proprietery installer for the company's platform, that only had a gui and no command-line options. Everything else, including a whole bunch of SQL stuff, I could do it remotely, on psh [3]. All this naturally pushed me to do more psh scripting, as it was easier to run a script than key in a dozen commends on the command-line. So I left that job feeling very comfortable with powershell, and although I didn't quite have to use it that much in any other job since, I still use it as my primary shell at home. ____________________ [1] I think it started with this article, whose title immediately caught my attention: http://www.howtogeek.com/117192/how-to-run-powershell-commands-on-remote-computers/ http://www.howtogeek.com/117192/how-to-run-powershell-comman... [2] Noone else cared to learn powershell. I did ask. They said they didn't want to have to learn a new programming language. To be fair, I never explained my remoting setup to anyone, because they would probably tell me to stop using it (I was just a junior dev at the time). Note also that I never enabled remoting on any of our public-facing servers, just in case there was some vulnerability that could be exploited. [3] I also used vim and netrw to edit my scripts on the remote server directly, over a UNC path, so I didn't have to re-upload them every time I needed to change them. This was a very Linux-y way to do stuff and really unusual where I worked.
- 13of40 10y agoIf you can get hold of either Bruce Payett or Lee Holm's PowerShell scripting books, those are pretty canonical guides, as both of those guys were devs on the PowerShell team for years. On day one you should get familiar with the discoverability features built in: get-member, get-help, get-command, get-member, tab completion, get-alias, etc.
- aytch 10y agoI just registered powershellbyexample.com - I'll start updating it soon!
- w4rh4wk5 10y agoThere is a well designed tutorial on Youtube, helped me a lot to get started. https://www.youtube.com/playlist?list=PL6D474E721138865A https://www.youtube.com/playlist?list=PL6D474E721138865A
- diminoten 10y agoI dunno if this is the kind of advice you're looking for, but what I've found is forcing myself to do everything with an unfamiliar tool helps a great deal.
- chris_wot 10y agoPowershell is frankly fairly amazing. Recently I found myself needing to open the Windows datastore.edb file, and before I discovered some interops I learned that in fact you can grab a C# member definition, then use it as a signature and load that type as a Powershell object [1] Hell, I even found a C# code snippet and was able to add into a Powershell string, then add this as a C# type definition, and Powershell compiled it to an assembly and then loaded it as an instance of a Powershell object.[2] 1. http://www.leeholmes.com/blog/2009/01/19/powershell-pinvoke-walkthrough/ http://www.leeholmes.com/blog/2009/01/19/powershell-pinvoke-... 2. I found how to do this here: https://blogs.technet.microsoft.com/stefan_gossner/2010/05/07/using-csharp-c-code-in-powershell-scripts/ https://blogs.technet.microsoft.com/stefan_gossner/2010/05/0...
- teyc 10y agoTo add further - I found out PInvoke over Powershell works just as well on OS X.
- kruptos 10y agoCan someone link a site that was posted on HN a month ago that shows side by side comparisons between BASH commands and Powershell?
- grzm 10y agoHave you tried the Search API below? You can search stories or comments. Here's a list of likely Powershell submissions: https://hn.algolia.com/?query=powershell&sort=byDate&prefix=false&page=0&dateRange=all&type=story https://hn.algolia.com/?query=powershell&sort=byDate&prefix=...
- agumonkey 10y agoI tried scripting the clipboard through vbscript but got stuck, tried powershell, it's a one liner. Seems like a pleasant platform. Thanks for this thread.
- manojlds 10y agoFor me it was this - https://stacktoheap.com/blog/2012/10/17/learning-by-answering-questions/ https://stacktoheap.com/blog/2012/10/17/learning-by-answerin... I started using Powershell and also started answering questions on SO. The latter helped a lot in quickly improving my skills.
- nunez 10y agoI still think Bruce Payette'a book on PowerShell is referential in explaining how PowerShell works inside-out. As far as learning it goes, there's no better practice than porting your old work!
- zupreme 10y agoThis may or may not work for you but it's now I forced myself to learn PowerShell. First you need to understand that PowerShell (because of WMI and .net snapins) can do literally anything that can be done on a windows environment either via click, keystroke, or code. Second you need to understand that PowerShell is an object-oriented scripting language. You can certainly use it in a procedural fashion, if you're so inclined, but you will be severely hobbling yourself in the process. Third you need to decide to write (or locate, test, and study) scripts to do a fair percentage of the things you might normally seek small single-purpose third party software to do. Want to scan your network for devices, use PowerShell. Want to bulk, edit AD users, do it in PowerShell. Need to clone a directory structure? You get the idea... Take this approach and look for legitimate reasons to use PowerShell every day.
- selmat 10y agoSeconded. In my last job i automated all tedious tasks via powershell. Need to verify connectivity and documentation accuracy (credentials, snmp strings, vendors, versions...)? Powershell is solution for me. Even tcl scripts was parsed, compared and exported to xls with Powershell. Verify and implement configuratiom template was another case where powershell was solution. For me this is my strongest weapon on windows automation and system management. And i like it beacuse you can edit in notepad++, sublime, atom, whatever...save... a run ps1 file. No insane and complex IDE needed, no compilers. If you need you can do exe files. It's dirty solution, but it works. My last project (app for coffe shopps and restaurants) is written in powershell. "The biggest issue" for me is support of my scripts on windows with lower version of powershell or .NET In regards to original question. "Powershell in action" is my favorite resource about powershell.
- deostroll 10y agopowershell does have its own command for normal scripting stuff...For e.g. Test-Path, etc...but if at all you are stuck with something you can always revert to the .net framework...but I still like curl hence I stuck to git bash