The Notes for Professionals book is compiled from Stack Overflow Documentation, the content is written by the beautiful people at Stack Overflow. Text content is released under Creative Commons BY-SA. See credits at the end of this book whom contributed to the various chapters. Images may be copyright of their respective owners unless otherwise specified
Book created for educational purposes and is not affiliated with group(s), company(s) nor Stack Overflow. All trademarks belong to their respective company owners
https://goalkicker.com/
章节目录
1-1
Content list
1-2
About
1-3
Chapter 1: Getting started with PowerShell
1-4
Section 1.1: Allow scripts stored on your machine to run un-signed
1-5
Section 1.2: Aliases & Similar Functions
1-6
Section 1.3: The Pipeline - Using Output from a PowerShell cmdlet
1-7
Section 1.4: Calling .Net Library Methods
1-8
Section 1.5: Installation or Setup
1-9
Section 1.6: Commenting
1-10
Section 1.7: Creating Objects
1-11
Chapter 2: Variables in PowerShell
1-12
Section 2.1: Simple variable
1-13
Section 2.2: Arrays
1-14
Section 2.3: List Assignment of Multiple Variables
1-15
Section 2.4: Scope
1-16
Section 2.5: Removing a variable
1-17
Chapter 3: Operators
1-18
Section 3.1: Comparison Operators
1-19
Section 3.2: Arithmetic Operators
1-20
Section 3.3: Assignment Operators
1-21
Section 3.4: Redirection Operators
1-22
Section 3.5: Mixing operand types, the type of the left operand dictates the behavior
1-23
Section 3.6: Logical Operators
1-24
Section 3.7: String Manipulation Operators
1-25
Chapter 4: Special Operators
1-26
Section 4.1: Array Expression Operator
1-27
Section 4.2: Call Operation
1-28
Section 4.3: Dot sourcing operator
1-29
Chapter 5: Basic Set Operations
1-30
Section 5.1: Filtering: Where-Object / where / ?
1-31
Section 5.2: Ordering: Sort-Object / sort
1-32
Section 5.3: Grouping: Group-Object / group
1-33
Section 5.4: Projecting: Select-Object / select
1-34
Chapter 6: Conditional logic
1-35
Section 6.1: if, else and else if
1-36
Section 6.2: Negation
1-37
Section 6.3: If conditional shorthand
1-38
Chapter 7: Loops
1-39
Section 7.1: Foreach
1-40
Section 7.2: For
1-41
Section 7.3: ForEach() Method
1-42
Section 7.4: ForEach-Object
1-43
Section 7.5: Continue
1-44
Section 7.6: Break
1-45
Section 7.7: While
1-46
Section 7.8: Do
1-47
Chapter 8: Switch statement
1-48
Section 8.1: Simple Switch
1-49
Section 8.2: Switch Statement with CaseSensitive Parameter
1-50
Section 8.3: Switch Statement with Wildcard Parameter
1-51
Section 8.4: Switch Statement with File Parameter
1-52
Section 8.5: Simple Switch with Default Condition
1-53
Section 8.6: Switch Statement with Regex Parameter
1-54
Section 8.7: Simple Switch With Break
1-55
Section 8.8: Switch Statement with Exact Parameter
1-56
Section 8.9: Switch Statement with Expressions
1-57
Chapter 9: Strings
1-58
Section 9.1: Multiline string
1-59
Section 9.2: Here-string
1-60
Section 9.3: Concatenating strings
1-61
Section 9.4: Special characters
1-62
Section 9.5: Creating a basic string
1-63
Section 9.6: Format string
1-64
Chapter 10: HashTables
1-65
Section 10.1: Access a hash table value by key
1-66
Section 10.2: Creating a Hash Table
1-67
Section 10.3: Add a key value pair to an existing hash table
1-68
Section 10.4: Remove a key value pair from an existing hash table
1-69
Section 10.5: Enumerating through keys and Key-Value Pairs
1-70
Section 10.6: Looping over a hash table
1-71
Chapter 11: Working with Objects
1-72
Section 11.1: Examining an object
1-73
Section 11.2: Updating Objects
1-74
Section 11.3: Creating a new object
1-75
Section 11.4: Creating Instances of Generic Classes
1-76
Chapter 12: PowerShell Functions
1-77
Section 12.1: Basic Parameters
1-78
Section 12.2: Advanced Function
1-79
Section 12.3: Mandatory Parameters
1-80
Section 12.4: Parameter Validation
1-81
Section 12.5: Simple Function with No Parameters
1-82
Chapter 13: PowerShell Classes
1-83
Section 13.1: Listing available constructors for a class
1-84
Section 13.2: Methods and properties
1-85
Section 13.3: Constructor overloading
1-86
Section 13.4: Get All Members of an Instance
1-87
Section 13.5: Basic Class Template
1-88
Section 13.6: Inheritance from Parent Class to Child Class
1-89
Chapter 14: PowerShell Modules
1-90
Section 14.1: Create a Module Manifest
1-91
Section 14.2: Simple Module Example
1-92
Section 14.3: Exporting a Variable from a Module
1-93
Section 14.4: Structuring PowerShell Modules
1-94
Section 14.5: Location of Modules
1-95
Section 14.6: Module Member Visibility
1-96
Chapter 15: PowerShell profiles
1-97
Section 15.1: Create an basic profile
1-98
Chapter 16: Calculated Properties
1-99
Section 16.1: Display file size in KB - Calculated Properties
1-100
Chapter 17: Using existing static classes
1-101
Section 17.1: Adding types
1-102
Section 17.2: Using the .Net Math Class
1-103
Section 17.3: Creating new GUID instantly
1-104
Chapter 18: Built-in variables
1-105
Section 18.1: $PSScriptRoot
1-106
Section 18.2: $Args
1-107
Section 18.3: $PSItem
1-108
Section 18.4: $?
1-109
Section 18.5: $error
1-110
Chapter 19: Automatic Variables
1-111
Section 19.1: $OFS
1-112
Section 19.2: $?
1-113
Section 19.3: $null
1-114
Section 19.4: $error
1-115
Section 19.5: $pid
1-116
Section 19.6: Boolean values
1-117
Section 19.7: $_ / $PSItem
1-118
Section 19.8: $PSVersionTable
1-119
Chapter 20: Environment Variables
1-120
Section 20.1: Windows environment variables are visible as a PS drive called Env:
1-121
Section 20.2: Instant call of Environment Variables with $env:
1-122
Chapter 21: Splatting
1-123
Section 21.1: Piping and Splatting
1-124
Section 21.2: Passing a Switch parameter using Splatting
1-125
Section 21.3: Splatting From Top Level Function to a Series of Inner Function
1-126
Section 21.4: Splatting parameters
1-127
Chapter 22: PowerShell "Streams"; Debug, Verbose, Warning, Error, Output and Information
1-128
Section 22.1: Write-Output
1-129
Section 22.2: Write Preferences
1-130
Chapter 23: Sending Email
1-131
Section 23.1: Send-MailMessage with predefined parameters
1-132
Section 23.2: Simple Send-MailMessage
1-133
Section 23.3: SMTPClient - Mail with .txt file in body message
1-134
Chapter 24: PowerShell Remoting
1-135
Section 24.1: Connecting to a Remote Server via PowerShell
1-136
Section 24.2: Run commands on a Remote Computer
1-137
Section 24.3: Enabling PowerShell Remoting
1-138
Section 24.4: A best practise for automatically cleaning-up PSSessions
1-139
Chapter 25: Working with the PowerShell pipeline
1-140
Section 25.1: Writing Functions with Advanced Lifecycle
1-141
Section 25.2: Basic Pipeline Support in Functions
1-142
Section 25.3: Working concept of pipeline
1-143
Chapter 26: PowerShell Background Jobs
1-144
Section 26.1: Basic job creation
1-145
Section 26.2: Basic job management
1-146
Chapter 27: Return behavior in PowerShell
1-147
Section 27.1: Early exit
1-148
Section 27.2: Gotcha! Return in the pipeline
1-149
Section 27.3: Return with a value
1-150
Section 27.4: How to work with functions returns
1-151
Section 27.5: Gotcha! Ignoring unwanted output
1-152
Chapter 28: CSV parsing
1-153
Section 28.1: Basic usage of Import-Csv
1-154
Section 28.2: Import from CSV and cast properties to correct type
1-155
Chapter 29: Working with XML Files
1-156
Section 29.1: Accessing an XML File
1-157
Section 29.2: Creating an XML Document using XmlWriter()
1-158
Section 29.3: Adding snippets of XML to current XMLDocument
1-159
Chapter 30: Communicating with RESTful APIs
1-160
Section 30.1: Post Message to hipChat
1-161
Section 30.2: Using REST with PowerShell Objects to GET and POST many items
1-162
Section 30.3: Use Slack.com Incoming Webhooks
1-163
Section 30.4: Using REST with PowerShell Objects to Get and Put individual data
1-164
Section 30.5: Using REST with PowerShell to Delete items
1-165
Chapter 31: PowerShell SQL queries
1-166
Section 31.1: SQLExample
1-167
Section 31.2: SQLQuery
1-168
Chapter 32: Regular Expressions
1-169
Section 32.1: Single match
1-170
Section 32.2: Replace
1-171
Section 32.3: Replace text with dynamic value using a MatchEvalutor
1-172
Section 32.4: Escape special characters
1-173
Section 32.5: Multiple matches
1-174
Chapter 33: Aliases
1-175
Section 33.1: Get-Alias
1-176
Section 33.2: Set-Alias
1-177
Chapter 34: Using the progress bar
1-178
Section 34.1: Simple use of progress bar
1-179
Section 34.2: Usage of inner progress bar
1-180
Chapter 35: PowerShell.exe Command-Line
1-181
Section 35.1: Executing a command
1-182
Section 35.2: Executing a script file
1-183
Chapter 36: Cmdlet Naming
1-184
Section 36.1: Verbs
1-185
Section 36.2: Nouns
1-186
Chapter 37: Running Executables
1-187
Section 37.1: GUI Applications
1-188
Section 37.2: Console Streams
1-189
Section 37.3: Exit Codes
1-190
Chapter 38: Enforcing script prerequisites
1-191
Section 38.1: Enforce minimum version of PowerShell host
1-192
Section 38.2: Enforce running the script as administrator
1-193
Chapter 39: Using the Help System
1-194
Section 39.1: Updating the Help System
1-195
Section 39.2: Using Get-Help
1-196
Section 39.3: Viewing online version of a help topic
1-197
Section 39.4: Viewing Examples
1-198
Section 39.5: Viewing the Full Help Page
1-199
Section 39.6: Viewing help for a specific parameter
1-200
Chapter 40: Modules, Scripts and Functions
1-201
Section 40.1: Function
1-202
Section 40.2: Script
1-203
Section 40.3: Module
1-204
Section 40.4: Advanced Functions
1-205
Chapter 41: Naming Conventions
1-206
Section 41.1: Functions
1-207
Chapter 42: Common parameters
1-208
Section 42.1: ErrorAction parameter
1-209
Chapter 43: Parameter sets
1-210
Section 43.1: Parameter set to enforce the use of a parameter when a other is selected
1-211
Section 43.2: Parameter set to limit the combination of parameters
1-212
Chapter 44: PowerShell Dynamic Parameters
1-213
Section 44.1: "Simple" dynamic parameter
1-214
Chapter 45: GUI in PowerShell
1-215
Section 45.1: WPF GUI for Get-Service cmdlet
1-216
Chapter 46: URL Encode/Decode
1-217
Section 46.1: Encode Query String with `[System.Web.HttpUtility]::UrlEncode()`
1-218
Section 46.2: Quick Start: Encoding
1-219
Section 46.3: Quick Start: Decoding
1-220
Section 46.4: Encode Query String with `[uri]::EscapeDataString()`
1-221
Section 46.5: Decode URL with `[uri]::UnescapeDataString()`
1-222
Section 46.6: Decode URL with `[System.Web.HttpUtility]::UrlDecode()`
1-223
Chapter 47: Error handling
1-224
Section 47.1: Error Types
1-225
Chapter 48: Package management
1-226
Section 48.1: Create the default PowerShell Module Repository
1-227
Section 48.2: Find a module by name
1-228
Section 48.3: Install a Module by name
1-229
Section 48.4: Uninstall a module my name and version
1-230
Section 48.5: Update a module by name
1-231
Section 48.6: Find a PowerShell module using a pattern
1-232
Chapter 49: TCP Communication with PowerShell
1-233
Section 49.1: TCP listener
1-234
Section 49.2: TCP Sender
1-235
Chapter 50: PowerShell Workflows
1-236
Section 50.1: Workflow with Input Parameters
1-237
Section 50.2: Simple Workflow Example
1-238
Section 50.3: Run Workflow as a Background Job
1-239
Section 50.4: Add a Parallel Block to a Workflow
1-240
Chapter 51: Embedding Managed Code (C# | VB)
1-241
Section 51.1: C# Example
1-242
Section 51.2: VB.NET Example
1-243
Chapter 52: How to download latest artifact from Artifactory using PowerShell script (v2.0 or below)?
1-244
Section 52.1: PowerShell Script for downloading the latest artifact
1-245
Chapter 53: Comment-based help
1-246
Section 53.1: Function comment-based help
1-247
Section 53.2: Script comment-based help
1-248
Chapter 54: Archive Module
1-249
Section 54.1: Compress-Archive with wildcard
1-250
Section 54.2: Update existing ZIP with Compress-Archive
1-251
Section 54.3: Extract a Zip with Expand-Archive
1-252
Chapter 55: Infrastructure Automation
1-253
Section 55.1: Simple script for black-box integration test of console applications