You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Docs/Intro/CoreElements_Intro.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,7 @@ In simple terms:
70
70
71
71
By default, Windows is shipped with conhost.exe, short for Console Host. This application is the default terminal application built into Windows that hosts command-line shells like Command Prompt and PowerShell, providing a basic interface for executing commands. First appeared in Windows 7, this terminal is super old, and in [this article](https://learn.microsoft.com/en-us/windows/console/definitions), Microsoft says that even though "conhost.exe will continue to be responsible for API call servicing and translation," "the user-interface components are intended to be delegated through a pseudoconsole to a terminal."
72
72
73
-
Anyway, my point is that if you want to do some proper scripting and interaction with the terminal, conhost.exe is not recommended. There are a lot more other options that are far better than conhost.exe, here is a incomplete list just for example:
73
+
Anyway, my point is that if you want to do some proper scripting and interaction with the terminal, conhost.exe is not recommended. There are a lot more other options that are far better than conhost.exe, here is an incomplete list just for example:
74
74
75
75
-[Hyper](https://hyper.is)
76
76
-[ConEmu](https://conemu.github.io)
@@ -85,9 +85,9 @@ In this project, I am using Windows Terminal, and I recommend you to use it too,
85
85
86
86
Now that you have learned the basics about the operating system, shell, and terminal. For more advanced information on related concepts, you can also visit Scott Hanselman's article: [What's the difference between a console, a terminal, and a shell?](https://www.hanselman.com/blog/whats-the-difference-between-a-console-a-terminal-and-a-shell)
87
87
88
-
You are ready to move on and start using the tools in this project. Don’t worry if you are still new - each tool comes with step-by-step setup guides to help you get started. You can use the following link to head back to the README.
88
+
You are ready to move on and start using the tools in this project. Don’t worry if you are still new. Each tool comes with step-by-step setup guides to help you get started. You can use the following link to head back to the main README.
Copy file name to clipboardExpand all lines: Docs/Intro/PowerShell_Intro.md
+28-16Lines changed: 28 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# A Brief Introduction to PowerShell
2
2
3
-
This document is my attempt at providing a comprehensive introduction to PowerShell to beginners. The document mainly introduces PowerShell's key features and advantages to provide reasons to try out PowerShell. Explanations of some basic scripting and programming concepts are also included. If you found the explanation of any of the concepts confusing, or some key concepts are missing in this document. Please leave an issue, and I will try my best to produce a clear explanation.
3
+
This document is my attempt at providing a comprehensive introduction to PowerShell to beginners. The document mainly introduces PowerShell's key features and advantages to provide reasons to try out PowerShell. Explanations of some basic scripting and programming concepts are also included. If you found the explanation of any of the concepts confusing, or some key concepts are missing in this document. Please [leave an issue](https://github.com/Alexander-556/PowerShellScripts/issues/new), and I will try my best to produce a clear explanation.
4
4
5
5
---
6
6
@@ -24,35 +24,37 @@ This document is my attempt at providing a comprehensive introduction to PowerSh
24
24
-[Error Handling](#error-handling)
25
25
-[Cmdlets to try](#cmdlets-to-try)
26
26
-[Basic Cmdlets](#basic-cmdlets)
27
+
-[File Operation](#file-operation)
28
+
-[Pipeline Practice](#pipeline-practice)
27
29
-[Feedbacks](#feedbacks)
28
30
29
31
## What is PowerShell?
30
32
31
-
[PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.5) is a powerful automation platform developed by Microsoft. It combines a command-line shell with a robust scripting language, all built on the .NET runtime. In our case, PowerShell allows us to automate tasks and solve everyday Windows annoyances with ease, thanks to its deep integration with the operating system.
33
+
[PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.5) is a powerful automation platform developed by Microsoft. It combines a shell with a robust scripting language, all built on the .NET runtime. In our case, PowerShell allows us to automate tasks and solve everyday Windows annoyances with ease, thanks to its deep integration with the operating system.
32
34
33
35
## PowerShell vs. Command Prompt: Key Differences
34
36
35
-
Most Windows users are more familiar with the Command Prompt (cmd.exe) - the black box that handles basic commands like `dir`, `copy`, `ping`, or `ipconfig`. Its history goes all the way back to the MS-DOS days. While CMD has served well for decades, it's showing its age in today’s more complex computing environment. PowerShell, on the other hand, is a modern, more powerful tool designed to meet today’s automation needs.
37
+
Most Windows users are more familiar with the Command Prompt (cmd.exe), the black box that handles basic commands like `dir`, `copy`, `ping`, or `ipconfig`. Its history goes all the way back to the MS-DOS days. While CMD has served well for decades, it's showing its age in today’s more complex computing environment. PowerShell, on the other hand, is a modern, more powerful tool designed to meet today’s automation needs.
36
38
37
39
Here are some key advantages of PowerShell over Command Prompt:
38
40
39
41
### Object-based input/output
40
42
41
-
PowerShell doesn't just deal with plain text. It works with structured objects, which means the output from one command can be passed to another with full access to properties and values.
43
+
PowerShell doesn't just deal with plain text. It works with structured objects, which means the output from one command can be passed to another with full access to properties and values. This feature allows for superior coding flexibility.
42
44
43
45
### Modern scripting capabilities
44
46
45
-
PowerShell supports variables, conditional logic, loops, functions, modules, and robust error handling - everything you’d expect from a full scripting language.
47
+
PowerShell supports variables, conditional logic, loops, functions, modules, and robust error handling, all the tools you will need and everything you would expect from a full scripting language.
46
48
47
49
### Standardized command naming and built-in help
48
50
49
-
PowerShell uses a consistent [Verb-Noun format](https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-7.5) like `Get-Process` or `Set-TimeZone`. This makes it easier to guess, discover, and remember commands. Plus, the [Get-Help](https://learn.microsoft.com/en-us/powershell/scripting/learn/ps101/02-help-system?view=powershell-7.5) command provides detailed syntax, parameter explanations, and usage examples — all available right from the terminal.
51
+
PowerShell uses a consistent [Verb-Noun format](https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-7.5) like `Get-Process` or `Set-TimeZone`. This makes it easier to guess, discover, and remember commands. Plus, the [Get-Help](https://learn.microsoft.com/en-us/powershell/scripting/learn/ps101/02-help-system?view=powershell-7.5) command provides detailed syntax, parameter explanations, and usage examples right from the terminal.
50
52
51
53
---
52
54
53
55
Combined with PowerShell's native integration into Windows, we can write scripts that easily interact with files, scheduled tasks, system settings, event logs, services, and even the registry. This opens up a wide range of possibilities for system automation and customization.
54
56
55
-
I hope the above paragraphs have given you enough reasons to at least give PowerShell a try. In the following sections, we’ll go over some of PowerShell’s core concepts - the building blocks that will help you become confident with this tool.
57
+
I hope the above paragraphs have given you enough reasons to at least give PowerShell a try. In the following sections, we’ll go over some of PowerShell’s core concepts, the building blocks that will help you become confident with this tool.
56
58
57
59
If you're ever curious to explore further, Microsoft has an excellent, beginner-friendly documentation site here:
@@ -75,7 +77,7 @@ For more details, on Cmdlets, go visit Microsoft's official documentation on:
75
77
76
78
#### Functions
77
79
78
-
PowerShell lets you define your own functions to group reusable blocks of code under a custom name. This is especially helpful when you want to make your code modular by encapsulate logic that you might use multiple times throughout a script. Functions are written using the function keyword and can accept parameters just like cmdlets.
80
+
PowerShell lets you define your own functions to group reusable blocks of code under a custom name. This is especially helpful when you want to make your code modular by encapsulate logic that you might use multiple times throughout a script. Functions are written using the `function` keyword and can accept parameters just like cmdlets.
79
81
80
82
As you grow more comfortable with scripting, writing your own functions becomes second nature and gives your scripts more structure and clarity. For more detailed information on functions, check out the following links to Microsoft's official PowerShell documentations:
@@ -92,25 +94,25 @@ More details on modules can be found at Microsoft's official documentation:
92
94
93
95
### Pipelines
94
96
95
-
Similar to Unix-like shells (like Bash or Zsh), PowerShell also supports the use of pipelines using the | operator. This operator lets you pass the output of one command directly into another, making it possible to chain commands together in a clean and readable way.
97
+
Similar to Unix-like shells (like Bash or Zsh), PowerShell also supports the use of pipelines using the `|` operator. This operator lets you pass the output of one command directly into another, making it possible to chain commands together in a clean and readable way.
96
98
97
-
The pipeline is especially handy when writing compact, powerful one-liners - allowing you to filter, sort, and transform data step by step, all in a single command.
99
+
The pipeline is especially handy when writing compact, powerful one-liners, allowing you to filter, sort, and transform data step by step, all in a single command.
In addition, PowerShell isn't just a command-line shell - it's a scripting language, and it supports many features common to other programming languages:
105
+
In addition, PowerShell isn't just a command-line shell. It's a scripting language, and it supports many features common to other programming languages:
104
106
105
107
#### Variables
106
108
107
-
You can store values in variables using the \$ sign (e.g., $value = 1). Variables can hold strings, numbers, arrays, and objects.
109
+
You can store values in variables using the \$ sign (e.g., $value = 1). Variables can hold strings, numbers, arrays, and objects. Typically, scripting language don't require a type declaration when you initialize the variable, and the type is usually determined during the interpretation of the code.
108
110
109
111
#### Control Flow
110
112
111
-
PowerShell gives you access to if statements, loops (for, foreach, while), and switch cases - all the tools you need to make your scripts smarter and more dynamic.
113
+
PowerShell gives you access to if statements, loops (for, foreach, while), and switch cases. These are all the control flow tools you would expect from a programming language.
112
114
113
-
Check out PowerShell's key works with the following link:
115
+
Check out PowerShell's key words with the following link:
This above command will show you a detailed explanation of the `Get-Process` cmdlet, including its description, parameters, and usage examples. You can also use these helpful flags:
129
131
130
132
```powershell
131
-
Get-Help Get-Process -Examples # Show practical examples
132
-
Get-Help Get-Process -Detailed # Show detailed information
133
+
Get-Help Get-Process -Examples # Show examples
134
+
Get-Help Get-Process -Detailed # Show some detailed information
133
135
Get-Help Get-Process -Online # Open the official docs in your browser
134
136
```
135
137
@@ -157,8 +159,14 @@ or visit the [Microsoft Approved Verbs Documentation](https://learn.microsoft.co
157
159
158
160
Since we are usually directly communicating with the Windows Operating System, proper error handling becomes very important to us. When writing automation scripts, we don't want fatal errors to come uncaught, and we also don't want a stream of "Unexpected Error" during debugging. That could be a nightmare. Luckily, PowerShell provides structured error handling using try, catch, and finally blocks. You run code that might go wrong in the try block. If some error occurred in the try block, code in the catch block will execute. Code in Finally block will always execute regardless of the error state. This allows you to build robust scripts that can customize error message and handle unexpected problems without crashing.
159
161
162
+
While just reading about these features could be boring. I suggest you to try these `try`, `catch`, and `finally` code blocks when you are comfortable with scripting. Just explore their behavior and you will see the value of these seemingly simple code blocks.
163
+
160
164
## Cmdlets to try
161
165
166
+
_Work in Progress..._
167
+
168
+
To give you a helpful start in using PowerShell, here are some example cmdlets that you can easily try after you set up your PowerShell environment
169
+
162
170
### Basic Cmdlets
163
171
164
172
```powershell
@@ -179,6 +187,10 @@ Set-Location C:\Users
179
187
180
188
Navigates to a different folder (like cd in CMD or Bash).
0 commit comments