Windows PowerShell, Should I memorize everything or can i just google it as needed

I’m currently taking a systems admin class, and it’s not my favorite, I love my java and javascript class but like HTML and CSS, PowerShell is kinda dull, it doesn’t feel like a robust language, but I need to learn it, what I’m wondering is should I learn it well enough to pass my tests and never look back or is it crucial and I should dive in and memorize and integrate it in my everyday life. Is it worth the extra stress?

1 Like

From how you describe it it sounds like you just haven’t done much with power shell yet. It’s nothing like css or html. You can do most things in it that you can in any scripting shell language.

I’ve been using it recently to deploy and configure some software on remote devices for example.

Super useful for security as well as you can query, find, aggregate and interrogate data across whole networks of devices as well as command and control those devices.

There are entirely powershell driven post exploitation frameworks for example as well http://www.powershellempire.com/

Any sort of windows management can be done in it including management of entire domains.

There’s no need to memorise everything though. No one can memorise whole languages.

3 Likes

Imo, shells in general are primarily an interface for you to interact with the computer. It is the text counterpart to using a GUI. Scripting is just an automation tool. It is not meant to be compared directly to programming languages like Java. Scripts are simply a convenient way to coordinate the execution of programs. For the most part, “commands” in a shell are just the names of programs, so you’re not memorizing a language, so much as you are memorizing the names of programs.

Disclaimer, I don’t use powershell, but I think the issue here is inherent to shells in general. If any experience powershell users think I’m off base here, please say so.

3 Likes

This is a little different for powershell as I understand. Powershell functions are a part of powershell itself (the language), made up of modules, not individual programs.

You can’t for example run Get-Uptime in cmd, its from a powershell module from the language its self.

2 Likes

Would you say this is an accurate assessment (below), or does it really not resemble unix shells/cmd?

PowerShell is C# + Windows function calls. You can write it as you would a C# program, or a shell script, or a one-liner.

To answer your question on memorization, it has built-in help.

Get-Command *keyword*
Get-Help FoundCmdlet -Examples # or -Full

The wildcard search is for whatever you’re searching for.

You can even pipe commands (called cmdlets [command-let] in PowerShell) like you can in Unix-like shells

I’ve seen beautiful automation that rivals anything Bash, Python, Java, or C# can do in PowerShell. Definitely give it a chance.

2 Likes

PowerShell is object-oriented vs text/stream like Bash/Zsh/etc. You interface with objects and functions, rather than text and files (but you can still handle I/O and files)

1 Like

Yes. It essentially helps you automate and make your life a living ease with your computer.

… The end results are probably similar but id say its structured a little different.

Results are easily queryable for example.

PS C:\Users\x\Documents> Get-FileHash -Algorithm MD5 -Path '.\Savings and Budget 2020.xlsx'

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
MD5             375146C4E8ADF3A388E56F5EE45B7347                                       C:\Users\x\Documents\Savings and Budget 2020.xlsx

The output can be really easily modified

PS C:\Users\x\Documents> Get-FileHash -Algorithm MD5 -Path '.\Savings and Budget 2020.xlsx' | Format-List


Algorithm : MD5
Hash      : 375146C4E8ADF3A388E56F5EE45B7347
Path      : C:\Users\x\Documents\Savings and Budget 2020.xlsx

Need only just the hash? Get just that object

PS C:\Users\alanm\Documents> Get-FileHash -Algorithm MD5 -Path '.\Savings and Budget 2020.xlsx' | Select-Object Hash

Hash
----
375146C4E8ADF3A388E56F5EE45B7347

Want to save it?

PS C:\Users\x\Documents> $a = Get-FileHash -Algorithm MD5 -Path '.\Savings and Budget 2020.xlsx'
PS C:\Users\x\Documents> $a

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
MD5             375146C4E8ADF3A388E56F5EE45B7347                                       C:\Users\x\Documents\Savings and Budget 2020.xlsx


PS C:\Users\x\Documents> $a.Hash
375146C4E8ADF3A388E56F5EE45B7347

You can start to see how easy it is to collect and manipulate data

4 Likes

Ah, I see why you guys like is so much.

@RainColt if you think this isn’t robust, stay out away from Unix shells…

Parse your IP address out of ifconfig

ifconfig                        |
grep  "inet "                   |
grep  --invert-match "cast"     |
egrep --only-matching           \
  "([0-9]{1,3}\.){3}[0-9]{1,3}" |
grep --invert-match  "^127"
2 Likes

Inb4 OP becomes Windows systems engineer automating Azure, Exchange, MS SQL Server, and Win2019R2 making $350k per year.

1 Like

Why do you think im trying to hone my Powershell skills at work :smiley:

1 Like

:wink:

Relevant:

(@RainColt please let me know if this is too far off the number or off topic for you and I’ll move this a more private conversation, but I do think the below link is somewhat relevant since you asked about integrating it into your every day life)

image

1 Like

I just used Powershell to output the names of files in a folder to a .txt file.

3 Likes

FTFY

image

dir -n -r > textfile.txt

I probably shouldn’t go more OT :smiley:

1 Like

Question:

Are these commands case sensitive?

Why do they feel the need to use both dashes and capitalization?

This is how you lose people. It’s a silly windows-ism that drives me up the wall. You either capitalize or use dashes. Don’t do both. It slows your typing down significantly and achieves no meaningful difference in anything, except annoying the fundamentalists like me.

/rant

Aside from that, your description of powershell makes me interested in checking it out.

No, this is how you win people. You can alias and trim down the cmdlets all you want. But being verbose has been proven by the authors of PowerShell and PowerShell courses to reinforce the learning.

No. You can also tab complete.

Positional parameters made sense during the development. This is well documented so if you forget Get-Help cmdlet will show you what is required and not.

Built-in aliases work just the same

1 Like

But I don’t want to learn. I want to have job security.

If tab complete fixes capitalization, I’m in.

I guess good documentation could potentially be a substitute for silly conventions.

1 Like

Those two things don’t coexist in information technology. Sorry.

2 Likes

ICWYDT