PowerShell Learning Diary

DAY 4 - First day of learning

Lesson for today?

As I mentioned earlier I want to start with Don Jones' PowerShell 4N00bs and I've decided to start with the first 5 chapters for one day. That may seem a lot at first, but three chapters are in fact information about the series and explanation what PowerShell actually is, a little bit of history and so on. I also presume that the installation of PowerShell has happened in advance.

The main focus will be:

- Your First Console Experience (p. 21-28)

That includes the sub-chapters:

- Launch PowerShell

- Check your version

- Run a command

- Files and Folders

- Exit

- A Good First Step


Reaction?

Launch PowerShell

Okay, I was a little bit surprised after launching PowerShell for the first time. Since I'm only hardly familiar with coding  or scripting, it seems that I was expecting some kind of UI. It does totally make sense, that there is none, but I realized that I felt completly lost at the beginning. Just the blue screen staring at me...

COME ON, DO SOMETHING

Check Your Version

The comand $PSVersionTable brings me the output instantly, cool thing. I've read that there are many different versions of PowerShell right now, including something like PowerShell Core. I do not want to bother with that right now.

Outputs working. First thing I tried, worked ✅

Run a Command

This chapter starts with Get-Process and it gives me a long list of apps and processes running on my surface. Not really sure what to make from this, but Don now focuses on aliases. Shortcut for commands. That sounds promising since I thougt that there are cmdlets that are rather long, include special characters and look kind of frightening for me. 

Unfortunately: there are different aliases for differen OS' and different PowerShell versions. Well, that sounds waaaay to complicated, doesn't it?

Fortunately: There is a thing called Tab completion. And that sounds like it is meant for me. Basically it works like this: If you start typing a command and hit tab, PowerShell will fill in a possible command name. This way you can "scroll" through the commands and don't have to remember every single command. A lot like in VS Code 😃

And of course, the more you type, the faster you find the right command. I think that could be my function. 

Files and Folders 

Last chapter for today. Let's do this. Don wants me to run Get-PSDrive to see...well, what do I see? I recognize my C:\ drive but also a lot of other stuff, I've no idea about. 

But now it's more about navigating and I should change the top level of my system drive: the command Set-Location \ brings me back one folder. The command Set-Location C:\ brings me automatically to my C:\ drive. Neat!

This remindes me of my youth: I'm five years old and my old man teaches me how to navigate through DOS. And guess what, the DOS commands seem to work in PowerShell pretty great. I instinctivly try cd.., dir and cls and they all work.

Just as I recognized those old DOS commands, Don explains that these work in PowerShell as well. Anyway, I'm a little bit proud of myself that I remembered them, before he told me 😊

Next task is to run Get-ChildItem (which is the same as the alias dir) to list the content of the location you're in right now. All clear.

Now we want to change the home folder. What's a home folder? Anyway, the comand Set-Location $home brings me to the path C:\Users\mroth. Good to know, but is it useful? I'm not sure yet.

I learned that PowerShell commands follow a specific rule like verb-subject and that it's always like this. Where does the $ come from and when do I use it? Is there some kind of rule?

Okay, now I'm going to create a new folder. Just by scripting lines. Now this starts to feel exciting and it seems to be fairly simple.

The command is as follows:

New-Item (to create a new item) -Path (name of the item) -ItemType (to define what kind of item). That makes sense and the example is this:

New-Item -Path 4n00bs -ItemType Directory 

This creates a new folder named 4n00bs in the location you've just been. In this case we've been in the home folder, aka C:\Users\mroth

It worked 😃

And would you look at that?! It actually worked.

I finish the day with the exit command to end the session and close PowerShell automatically.

I guess this was a good start and I feel like I've learned a lot. And I have the feeling that this might work if I make the time to dig into it regurlarly 🎓


Learning?

I've learned that it feels strange if there's no UI but nevertheless I learned how to navigate in PowerShell (okay, just a bit, but still).

The old DOS commands seem to work in PowerShell

I now know how to create a new Folder in a certain path (and that feels really good)

Commands I've used:

  • $PSVersionTable
  • Get-Process
  • Set-Location \
  • Get-ChildItem
  • Set-Location $home
  • New-Item (-Path XX -ItemType XX)
  • exit

Next steps?

Next chapter is called "Where Do Commands Come From?" and it seems to talk about commands (easypeasy, I've already use some 😁) and modules (🤷‍♂️).

I'm really looking forward to it and hope my progress will be as smooth as this start, but somehow I doubt it. This scripting thing still feels uncomfortable. But at the same time I feel like I would've made a small step into something really big and that feels exciting.