-
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
23 changed files
with
292 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
- Dynamic typing | ||
- Case insensitive | ||
- Everything is object, more than plain text in shell. |
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
File renamed without changes.
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
19 changes: 19 additions & 0 deletions
19
docs/document/Powershell/docs/File System/3.Special Folders.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,19 @@ | ||
# Special Folders | ||
|
||
## Home Directory | ||
|
||
- `$HOME` | ||
- `$env:USERPROFILE` | ||
|
||
## Temp Folder | ||
|
||
- `$env:TMP` | ||
- `$env:TEMP` | ||
|
||
## APPDATA | ||
|
||
- `$env:APPDATA` | ||
|
||
## LOCALAPPDATA | ||
|
||
- `$env:LOCALAPPDATA` |
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
docs/document/Powershell/docs/File System/5.Write to File.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,13 @@ | ||
# Write to File | ||
|
||
|
||
|
||
## Redirection Operator | ||
|
||
Redirection operator in powershell is a shorthand for `Out-File`, to mimic the same thing in bash. | ||
|
||
```ps1 | ||
ls > foo.txt | ||
# equivalent to | ||
ls | Out-File foo.txt | ||
``` |
31 changes: 31 additions & 0 deletions
31
docs/document/Powershell/docs/File System/6.Serialization.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,31 @@ | ||
# Serialization | ||
|
||
> [!TIP] | ||
> For deserialization, see `gcm -Verb Import` | ||
## JSON | ||
|
||
```ps1 | ||
ls | ConverTo-JSON | ||
ls | ConverTo-JSON > foo.json | ||
``` | ||
|
||
## XML | ||
|
||
Powershell has a special xml format for itself called `Clixml`, this is specific to powershell. | ||
|
||
```ps1 | ||
ls | Export-Clixml foo.xml | ||
``` | ||
|
||
|
||
## CSV | ||
|
||
```ps1 | ||
ls | ConverTo-Csv > foo.csv | ||
ls | Export-Csv foo.csv | ||
``` | ||
|
||
## HTML | ||
|
||
## TXT |
File renamed without changes.
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,6 @@ | ||
# Comment | ||
|
||
## Single Line | ||
|
||
## Multiple Lines | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,9 @@ | ||
# String | ||
|
||
## String Interpolation | ||
|
||
## Raw String | ||
|
||
## String Concatenation | ||
|
||
## Character Escaping |
File renamed without changes.
36 changes: 36 additions & 0 deletions
36
docs/document/Powershell/docs/Modulization/Command Conflicts.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,36 @@ | ||
# Command Conflicts | ||
|
||
Commands from modules usually ships with a prefixed name to distinguish name conflicts. | ||
`Az` module for example, it always prefix its commands with `Az`. | ||
|
||
```console | ||
$ gcm Get*Az* | select -First 5 | ||
|
||
CommandType Name Version Source | ||
----------- ---- ------- ------ | ||
Alias Get-AzADServicePrincipalCredential 7.6.0 Az.Resources | ||
Alias Get-AzAksClusterUpgradeProfile 6.0.4 Az.Aks | ||
Alias Get-AzApplicationGatewayAvailableSslOptions 7.10.0 Az.Network | ||
Alias Get-AzApplicationGatewayAvailableWafRuleSets 7.10.0 Az.Network | ||
Alias Get-AzApplicationGatewayBackendHttpSettings 7.10.0 Az.Network | ||
``` | ||
|
||
## Command Fullname | ||
|
||
One solution is specifying the fullname of the command. | ||
|
||
```ps1 | ||
ModuleName\Get-Foo # use `\` as separator | ||
``` | ||
|
||
## Add Custom Prefix | ||
|
||
If a module doesn't have a prefix for its cmdlet, you can customize prefix for it on import. | ||
|
||
```ps1 | ||
ipmo '<module>' -Prefix Foo | ||
# assuming `Get-Bar` is from `<module>` | ||
# `Get-Bar` -> `Get-FooBar` | ||
Get-FooBar | ||
``` | ||
|
63 changes: 63 additions & 0 deletions
63
docs/document/Powershell/docs/Modulization/Load Modules.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,63 @@ | ||
# Load Modules | ||
|
||
## Custom Module Path | ||
|
||
Powershell automatically scans modules at certain locations. | ||
Inspect existing module path by: | ||
|
||
:::code-group | ||
```ps1[Windows] | ||
$env:PSModulePath -split ';' # windows | ||
``` | ||
```ps1[Linux/Mac] | ||
$env:PSModulePath -split ':' # linux/mac | ||
``` | ||
::: | ||
|
||
You can add your module location inside your profile file. | ||
|
||
```ps1 | ||
$env:PSModulePath += [IO.Path]::PathSeparator + '<path>' | ||
``` | ||
|
||
## Lazy Loading | ||
|
||
Powershell lazily loads a module when member from it is called. | ||
|
||
## Loaded Modules | ||
|
||
Inspect all loaded modules in current session: | ||
|
||
```ps1 | ||
Get-Module | ||
``` | ||
|
||
Check whether certain module name is loaded: | ||
|
||
```ps1 | ||
Get-Module -Name '<name>' | ||
``` | ||
|
||
> [!TIP] | ||
> Use `gmo` alias for `Get-Module`. | ||
## Import Modules | ||
|
||
Import a module in current session. | ||
|
||
```ps1 | ||
Import-Module -Name '<name>' | ||
``` | ||
> [!TIP] | ||
> Use `ipmo` alias for `Import-Module`. | ||
## Unload Modules | ||
|
||
Unload a module from current session. | ||
|
||
```ps1 | ||
Remove-Module '<name>' | ||
``` | ||
|
||
> [!TIP] | ||
> Use `rmo` alias for `Remove-Module`. |
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,42 @@ | ||
# Modules | ||
|
||
## Add Module Repository | ||
|
||
Module repository is a registry of powershell modules. | ||
It can be public or privately hosted by yourself. | ||
|
||
```ps1 | ||
Register-PSRepository <url> | ||
``` | ||
|
||
## Install a Module | ||
|
||
```ps1 | ||
Install-Module <name> | ||
``` | ||
|
||
## Search Modules | ||
|
||
Search module to be installed in registered repositories. | ||
|
||
```ps1 | ||
Find-Module <pattern> | ||
``` | ||
|
||
## Custom Module Path | ||
|
||
Powershell automatically scans modules at certain locations. | ||
Inspect existing module path by: | ||
|
||
:::code-group | ||
```ps1[Windows] | ||
$env:PSModulePath -split ';' # windows | ||
``` | ||
```ps1[Linux/Mac] | ||
$env:PSModulePath -split ':' # linux/mac | ||
``` | ||
::: | ||
|
||
```ps1 | ||
$env:PSModulePath += [IO.Path]::PathSeparator + '<path>' | ||
``` |
9 changes: 9 additions & 0 deletions
9
docs/document/Powershell/docs/Object Manipulation/1.Overview.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,9 @@ | ||
# Overview | ||
|
||
Powershell is a Object-Oriented shell language, so inspection and manipulation on objects is the fundamental capability to work with. | ||
|
||
This section focuses on how to work with objects, including: | ||
|
||
- LINQ like transformation over objects. | ||
- Object comparison. | ||
- Serialization and Deserialization. |
49 changes: 49 additions & 0 deletions
49
docs/document/Powershell/docs/Object Manipulation/Compare Objects.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,49 @@ | ||
# Compare Objects | ||
|
||
> [!TIP] | ||
> Use `diff` or `compare` alias for `Compare-Object` | ||
`Compare-Object` is a cmdlet to compare two sources of objects and returns a indicator implying the difference between the two. | ||
|
||
`-ReferenceObject` is the base object to compare, `-DifferenceObject` is the right hand side. | ||
|
||
```ps1 | ||
Compare-Object -ReferenceObject @('abc', 'dfg', 4) -DifferenceObject @('fg', 'abc', 1) | ||
``` | ||
|
||
```console | ||
InputObject SideIndicator | ||
----------- ------------- | ||
fg => | ||
1 => | ||
dfg <= | ||
4 <= | ||
``` | ||
|
||
- `<=` implies the difference content came from the `-ReferenceObject` | ||
- `=>` implies the difference content came from the `-DifferenceObject` | ||
- `==` implies the content appeared in both sides. | ||
|
||
> [!NOTE] | ||
> `Compare-Object` hides `==` case by default. Use `-IncludeEqual` to display it. And `-ExcludeDifferent` to to hide different cases. | ||
```ps1 | ||
diff -ref @('abc', 'dfg', 4) -diff @('fg', 'abc', 1) -IncludeEqual | ||
``` | ||
|
||
## Compare by Property | ||
|
||
You can specify which property to compare. | ||
|
||
```ps1 | ||
diff @('abc', 'dfg') @('fg', 'abc') -Property Length # compare on string.Length | ||
``` | ||
|
||
## Comparison Solution | ||
|
||
`Compare-Object` will try finding a method to do the comparison, falls back as following: | ||
|
||
- `IComparable` interface | ||
- `ToString()` and compare on string | ||
|
||
> [!TIP] | ||
> If the object to be compared doesn't implement `IComparable`, you should use `-Property`. |
8 changes: 8 additions & 0 deletions
8
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Object Members | ||
|
||
> [!TIP] | ||
> Use `gm` alias for `Get-Member`. | ||
```ps1 | ||
ls | Get-Member | ||
``` |
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 @@ | ||
# Select |
Empty file.