-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
261 additions
and
36 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
docs/document/Powershell/docs/File System/Units of Size.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Units of Size | ||
|
||
Powershell has builtin suffix for some numeric types that can represent file size and memory size like `mb`, `gb` and so on. | ||
Powershell recognized the units and convert it into the base representation of size which is `byte`. | ||
So it's like some implicit operators in `C++` that do the job for us. | ||
|
||
- **NOT** case-sensitive | ||
- Auto converts into bytes(the default unit) | ||
- No concrete or wrapper type exists, just a annotation. | ||
|
||
|
||
```ps1 | ||
gci | where { $_.Length > 1kb } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Control Flow | ||
|
||
## Falsy Values | ||
|
||
- `$false` | ||
- `$null` | ||
- Empty string | ||
- Numeric zeros | ||
- Empty collections implemented `IList`. | ||
|
||
> [!NOTE] | ||
> You can cast falsy values to boolean. | ||
>```ps1 | ||
>[bool]@() # False | ||
>``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# HashTable | ||
|
||
## Merging | ||
|
||
```ps1 | ||
@{ foo = 123; bar = '123' } + @{ baz = 234 } | ||
``` | ||
|
||
> [!WARNING] | ||
> `+` will throw if the two have any duplicated key. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Keyword Operators | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Scope | ||
|
||
Variables and functions can have a explicit scope. | ||
|
||
```ps1 | ||
$<scope>:foo = 1 | ||
function <scope>:Foo {} | ||
``` | ||
|
||
## Scope Modifier | ||
|
||
- `global`: accessible for the whole session. The root parent scope in a runspace. | ||
- `local`: default. Accessible in current script or script block or function. Can be accessed by child scopes. | ||
- `private`: accessible for current scope, meaning it can't be accessed by any other scope. | ||
- `script`: only accessible in script module. The default scope in a | ||
- Scopes from PSProviders | ||
- `env`: environment variables | ||
- `alias`: alias | ||
- `function` | ||
- `variable` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ echo $var | |
``` | ||
|
||
## Scope | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
docs/document/Powershell/docs/Object Manipulation/Object Members.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Terminology | ||
|
||
Powershell has its own terminologies besides other shells like bash. | ||
It's a shell integrated with .NET, it's not a independent platform. | ||
|
||
- `cmdlet`: builtin utils inside powershell, implemented using other languages like `C#`. | ||
- `function`: a command implemented using powershell language itself. | ||
- `application`: external executable. | ||
|
||
## Session | ||
|
||
Session is an environment state created on Powershell instance starts. | ||
A session is not a scope, all environment of sessions are isolated. | ||
The scope of the session is the top scope. | ||
|
||
## Runspace | ||
|
||
Runspace is a customized instance of Powershell by powershell code. | ||
In general, you can't control how powershell loads Providers and builtin member and so on. | ||
So Powershell exposes such api to create a customized object to represent the truncated or enhanced instance of the Powershell environment. | ||
By this approach, you can expose minimal privileges and custom utilities to users for certain tasks. | ||
|
||
Each Runspace creates isolated session state just like a normal powershell instance. | ||
|
||
A normal powershell can be referred as a Runspace too. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# | ||
|
||
Overview of pipeline in powershell: | ||
|
||
- A cmdlet can have multiple parameters that accept pipeline input. | ||
- Only one parameter can bind to a given pipeline object at a time. | ||
- PowerShell prioritizes by value over by property name. | ||
|
||
## Pipeline Parameter Binding | ||
|
||
|
||
## How Cmdlet Accept a Pipeline Input | ||
|
||
There's two solution when a pipeline input comes in as a fallback: | ||
|
||
- ByValue: accepts when the coming object can be cast to the target type of the parameter. | ||
- ByPropertyName: accepts when the coming object has property name matched to any parameter name of the cmdlet. | ||
|
||
|
||
```ps1 | ||
spps -Name (gci -File | foreach Name) | ||
# is equivalent to | ||
# because FileInfo has Name which matches to -Name parameter of spps cmdlet | ||
gci -File | spps | ||
``` | ||
|
||
> [!WARNING] | ||
> If multiple matches exist on ByPropertyName solution, powershell throws an error since these paramters might not be allowed to be used together. | ||
By value is always tried first, and then use ByPropertyName, or it finally throws. | ||
A parameter accepts pipeline input does not necessarily have both solutions, it can have at least one of them. |