mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-06-08 18:57:12 +00:00
remove mkdocs specific syntax
This commit is contained in:
parent
8d08c1964f
commit
8026e1465b
77 changed files with 1128 additions and 1128 deletions
|
@ -11,20 +11,20 @@ If you do call a cmdlet/PS function with parentheses, it is the same as passing
|
|||
|
||||
## Screen Output
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
Write-Host "message"
|
||||
```
|
||||
|
||||
## User Input
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
# Reading a value from input:
|
||||
$variable = Read-Host "prompt"
|
||||
```
|
||||
|
||||
## Variables
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
# Declaration
|
||||
[type]$var = value
|
||||
$var = value -as [type]
|
||||
|
@ -52,7 +52,7 @@ Write-Host (<expression>)
|
|||
|
||||
### Built-in Variables
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
$True, $False # boolean
|
||||
$null # empty value
|
||||
$? # last program return value
|
||||
|
@ -71,7 +71,7 @@ $Args # Unbound arguments
|
|||
|
||||
### Lists & Dictionaries
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
$List = @(5, "ice", 3.14, $True) # Explicit syntax
|
||||
$List = 2, "ice", 3.14, $True # Implicit syntax
|
||||
$List = (1..10) # Inclusive range
|
||||
|
@ -93,7 +93,7 @@ foreach ($k in $Dict.keys) {
|
|||
|
||||
## Flow Control
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
if (condition) {
|
||||
# Code here
|
||||
} elseif (condition) {
|
||||
|
@ -113,7 +113,7 @@ if (condition) {
|
|||
- **File**: Takes input from a file rather than a value statement. If multiple File parameters are included, only the last one is used. Each line of the file is read and evaluated by the Switch statement. The comparison is case-insensitive.
|
||||
- **Regex**: Performs regular expression matching of the value to the condition. If the match clause is not a string, this parameter is ignored. The comparison is case-insensitive. The `$matches` automatic variable is available for use within the matching statement block.
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
switch(variable) {
|
||||
20 { "Exactly 20"; break }
|
||||
{ $_ -eq 42 } { "The answer equals 42"; break }
|
||||
|
@ -142,7 +142,7 @@ switch [-regex|-wildcard|-exact][-casesensitive] -file filename
|
|||
|
||||
### Loops
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
# The classic for
|
||||
for(setup; condition; iterator) {
|
||||
# Code here
|
||||
|
@ -169,7 +169,7 @@ do {
|
|||
|
||||
### Operators
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
# Conditionals
|
||||
$a -eq $b # is equal to
|
||||
$a -ne $b # in not equal to
|
||||
|
@ -186,7 +186,7 @@ $True -Or $False
|
|||
|
||||
### Exception Handling
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
try {} catch {} finally {}
|
||||
try {} catch [System.NullReferenceException] {
|
||||
echo $_.Exception | Format-List -Force
|
||||
|
@ -195,7 +195,7 @@ try {} catch [System.NullReferenceException] {
|
|||
|
||||
## [Functions](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions?view=powershell-7)
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
function func() {}
|
||||
|
||||
# function with named parameters
|
||||
|
@ -221,7 +221,7 @@ If the function defines a `Begin`, `Process` or `End` block, all the code **must
|
|||
|
||||
If the function has a `Process` keyword, each object in `$input` is removed from `$input` and assigned to `$_`.
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
function [<scope:>]<name> [([type]$parameter1[,[type]$parameter2])]
|
||||
{
|
||||
param([type]$parameter1 [,[type]$parameter2]) # other way to specify named parameters
|
||||
|
@ -236,7 +236,7 @@ function [<scope:>]<name> [([type]$parameter1[,[type]$parameter2])]
|
|||
|
||||
Optionally, it's possible to provide a brief help string that describes the default value of the parameter, by adding the `PSDefaultValue` attribute to the description of the parameter, and specifying the `Help` property of `PSDefaultValue`.
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
function Func {
|
||||
param (
|
||||
[PSDefaultValue(Help = defValue)]
|
||||
|
@ -249,7 +249,7 @@ function Func {
|
|||
|
||||
### Parsing Script Arguments
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
$args # array of passed arguments
|
||||
$args[$index] # access to the arguments
|
||||
$args.count # number of arguments
|
||||
|
@ -259,7 +259,7 @@ $args.count # number of arguments
|
|||
|
||||
In `scripts.ps1`:
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
param($param1, $param2, ...) # basic usage
|
||||
param($param1, $param2=defvalue, ...) # with default values
|
||||
param([Type] $param1, $param2, ...) # specify a type
|
||||
|
@ -270,7 +270,7 @@ param([switch]$flag=$false, ...) # custom flags
|
|||
|
||||
In PowerShell:
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
.\script.ps1 arg1 arg2 # order of arguments will determine which data goes in which parameter
|
||||
|
||||
.\script.ps1 -param2 arg2 -param1 arg1 # custom order
|
||||
|
@ -280,7 +280,7 @@ In PowerShell:
|
|||
|
||||
A filter is a type of function that runs on each object in the pipeline. A filter resembles a function with all its statements in a `Process` block.
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
filter [<scope:>]<name> {<statement list>}
|
||||
```
|
||||
|
||||
|
@ -288,14 +288,14 @@ filter [<scope:>]<name> {<statement list>}
|
|||
|
||||
The syntax for comment-based help is as follows:
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
# .<help keyword>
|
||||
# <help content>
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
<#
|
||||
.<help keyword>
|
||||
<help content>
|
||||
|
@ -322,7 +322,7 @@ The description of a parameter. Add a `.PARAMETER` keyword for each parameter in
|
|||
|
||||
Type the parameter name on the same line as the `.PARAMETER` keyword. Type the parameter description on the lines following the `.PARAMETER` keyword. Windows PowerShell interprets all text between the `.PARAMETER` line and the next keyword or the end of the comment block as part of the parameter description. The description can include paragraph breaks.
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
.PARAMETER <Parameter-Name>
|
||||
```
|
||||
|
||||
|
@ -332,7 +332,7 @@ You can also specify a parameter description by placing a comment in the functio
|
|||
|
||||
If you use both a syntax comment and a `.PARAMETER` keyword, the description associated with the `.PARAMETER` keyword is used, and the syntax comment is ignored.
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Short description here
|
||||
|
@ -389,7 +389,7 @@ The keywords that describe the intended use of the function. The **Functionality
|
|||
|
||||
Redirects to the help topic for the specified command. You can redirect users to any help topic, including help topics for a function, script, cmdlet, or provider.
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
# .FORWARDHELPTARGETNAME <Command-Name>
|
||||
```
|
||||
|
||||
|
@ -397,7 +397,7 @@ Redirects to the help topic for the specified command. You can redirect users to
|
|||
|
||||
Specifies the help category of the item in `.ForwardHelpTargetName`. Valid values are `Alias`, `Cmdlet`, `HelpFile`, `Function`, `Provider`, `General`, `FAQ`, `Glossary`, `ScriptCommand`, `ExternalScript`, `Filter`, or `All`. Use this keyword to avoid conflicts when there are commands with the same name.
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
# .FORWARDHELPCATEGORY <Category>
|
||||
```
|
||||
|
||||
|
@ -406,7 +406,7 @@ Specifies the help category of the item in `.ForwardHelpTargetName`. Valid value
|
|||
Specifies a session that contains the help topic. Enter a variable that contains a **PSSession** object. This keyword is used by the [Export-PSSession](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/export-pssession?view=powershell-7)
|
||||
cmdlet to find the help topics for the exported commands.
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
# .REMOTEHELPRUNSPACE <PSSession-variable>
|
||||
```
|
||||
|
||||
|
@ -414,7 +414,7 @@ cmdlet to find the help topics for the exported commands.
|
|||
|
||||
Specifies an XML-based help file for the script or function.
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
# .EXTERNALHELP <XML Help File>
|
||||
|
||||
```
|
||||
|
@ -425,7 +425,7 @@ The `.ExternalHelp` keyword takes precedence over other comment-based help keywo
|
|||
|
||||
If the function is exported by a module, set the value of the `.ExternalHelp` keyword to a filename without a path. `Get-Help` looks for the specified file name in a language-specific subdirectory of the module directory. There are no requirements for the name of the XML-based help file for a function, but a best practice is to use the following format:
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
<ScriptModule.psm1>-help.xml
|
||||
```
|
||||
|
||||
|
@ -439,7 +439,7 @@ For more information about the cmdlet help XML-based help file format, see [How
|
|||
|
||||
### Classes
|
||||
|
||||
```ps1 linenums="1"
|
||||
```ps1
|
||||
[class]::func() # use function from a static class
|
||||
[class]::attribute # access to static class attribute
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue