وبلاگ بلیان

Mastering PowerShell

معرفی کتاب «Mastering PowerShell» نوشتهٔ Weltner T.. این کتاب در 517 صفحه، فرمت pdf، زبان انگلیسی ارائه شده است. «Mastering PowerShell» در دستهٔ بدون دسته‌بندی قرار دارد.

Copyright 2 About the Author 3 Acknowledgments 4 Mastering PowerShell 5 The PowerShell Console 6 Starting PowerShell 7 First Steps with the Console 8 Incomplete and Multi-line Entries 9 Important Keyboard Shortcuts 10 Deleting Incorrect Entries 10 Overtype Mode 11 Command History: Reusing Entered Commands 11 Automatically Completing Input 12 Scrolling Console Contents 13 Selecting and Inserting Text 13 QuickEdit Mode 13 Standard Mode 14 Customizing the Console 14 Opening Console Properties 14 Defining Options 15 Specifying Fonts and Font Sizes 15 Setting Window and Buffer Size 17 Selecting Colors 17 Directly Assigning Modifications in PowerShell 18 Saving Changes 19 Piping and Routing 19 Piping: Outputting Information Page by Page 19 Redirecting: Storing Information in Files 19 Summary 21 Interactive PowerShell 24 PowerShell as a Calculator 24 Calculating with Number Systems and Units 25 Executing External Commands 28 Starting the "Old" Console 29 Discovering Useful Console Commands 29 Security Restrictions at Program Start 32 Trustworthy Subdirectories 33 Cmdlets: "Genuine" PowerShell Commands 34 Using Parameters 37 Using Named Parameters 42 Switch Parameter 43 Positional Parameters 44 Common Parameters 44 Aliases: Giving Commands Other Names 46 Resolving Aliases 46 Creating Your Own Aliases 49 Removing—or Permanently Retaining—an Alias 49 Overwriting Alias Definitions and Deleting Them Manually 50 Functions: "Expanded" Aliases 51 Calling Commands with Arguments 51 Creating Shortcut Commands 52 Invoking Files and Scripts 52 Starting Scripts 53 Running Batch Files 53 Running VBScript Files 54 Running PowerShell Scripts 55 Summary 56 Variables 58 Your Own Variables 59 Selecting Variable Names 59 Assigning and Returning Values 60 Populating Several Variables with Values Simultaneously 60 Exchanging the Contents of Variables 61 Assigning Different Values to Several Variables 61 Overview of Variables in Use 62 Finding Variables 62 Verify Whether a Variable Exists 63 Deleting Variables 63 Using Special Variable Cmdlets 63 Write-Protecting Variables: Creating Constants 64 Variables with Description 66 "Automatic" PowerShell Variables 67 Environment Variables 70 Reading Particular Environment Variables 70 Searching for Environment Variables 70 Creating New Environment Variables 71 Deleting and Modifying Environment Variables 71 Permanent Modifications of Environment Variables 72 Drive Variables 73 Directly Accessing File Paths 73 Ad-hoc Variables: Sub-Expressions 75 Scope of Variables 76 Automatic Restriction 76 Changing Variable Visibility 77 Advantage of Lifting Visibility Restrictions: Clear and Unambiguous Start Conditions 77 Setting the Scope of Individual Variables 79 Variable Types and "Strongly Typing" 82 Assigning Fixed Types 83 The Advantages of Specialized Types 84 Variable Management: Behind the Scenes 87 Subsequent Modification of Variables Options 88 Activating Write-Protection 89 Type Specification of Variables 90 Verifying and Validating Variable Contents 90 Summary 93 Arrays and Hash Tables 95 PowerShell Commands Return Arrays 95 Storing Results in Arrays 96 Further Processing of Array Elements in a Pipeline 97 Working with Real Objects 98 Creating New Arrays 99 Polymorphic Arrays 100 Arrays With Only One (Or No) Element 100 Addressing Array Elements 101 Choosing Several Elements from an Array 101 Adding Elements to an Array and Removing Them 102 Using Hash Tables 103 Creating a New Hash Table 103 Storing Arrays in Hash Tables 104 Inserting New Keys in an Existing Hash Table 105 Modifying and Removing Values 105 Using Hash Tables for Output Formatting 106 Copying Arrays and Hash Tables 107 Strongly Typed Arrays 108 Summary 108 The PowerShell Pipeline 110 Using the PowerShell Pipeline 111 Object-oriented Pipeline 111 Text Not Converted Until the End 112 Streaming: Real-time Processing or Not? 114 "Blocking" Pipeline Commands 114 Converting Objects into Text 116 Making Object Properties Visible 116 Formatting Pipeline Results 118 Displaying Particular Properties 118 Using Wildcard Characters 119 Scriptblocks and "Synthetic" Properties 120 Changing Column Headings 121 Optimizing Column Width 121 PropertySets and Views 122 Sorting and Grouping Pipeline Results 124 Sort Object and Hash Tables 124 Grouping Information 125 Using Grouping Expressions 126 Using Formatting Cmdlets to Form Groups 128 Filtering Pipeline Results 129 Filtering Objects Out of the Pipeline 129 Selecting Object Properties 132 Limiting Number of Objects 134 Processing All Pipeline Results Simultaneously 136 Removing Doubles 137 Analyzing and Comparing Results 138 Statistical Calculations 138 Comparing Objects 139 Comparing Before-and-After Conditions 139 Detecting Changes to Objects 140 Comparing File Contents 143 Saving Snapshots for Later Use 144 Exporting Pipeline Results 145 Suppressing Results 146 Changing Pipeline Formatting 146 Forcing Text Display 147 Excel: Exporting Objects 148 HTML Outputs 149 The Extended Type System (Part One) 150 Rendering Text as Text and Only Text 151 Your Wish Has Priority 151 Known Objects and Formatting 152 Unknown Objects 153 Emergency Mode 154 "The Case of the Vanished Column" 154 ETS Enhancement 155 Planning Enhancement 155 Summary 159 Using Objects 160 Objects = Properties + Methods 161 Creating a New Object 161 Adding Properties 161 Adding Methods 163 Properties: What an Object "Is" 164 Properties Containing Objects 166 Read-Only and Read-Write Properties 167 Property Types 168 Listing All Properties 172 Methods: What an Object "Can Do" 173 Eliminating "Internal" Methods 174 Get_ and Set_ Methods 174 Standard Methods 174 Calling a Method 175 Call Methods with Arguments 175 Which Arguments are Required? 176 Low-Level Functions 177 Several Method "Signatures" 177 Playing with PromptForChoice 179 Working with Real-Life Objects 180 Storing Results in Variables 180 Using Object Properties 181 PowerShell-Specific Properties 182 Using Object Methods 183 Different Method Types 185 Using Static Methods 186 Finding Interesting .NET Types 191 Converting Object Types 191 Using Static Type Members 191 Using Dynamic Object Instance Members 192 Listing Assemblies 192 Finding Interesting Classes (Types) 193 Looking for Methods 196 Creating New Objects 196 Creating New Objects with New-Object 197 Using Constructors 197 New Objects by Conversion 198 Loading Additional Assemblies: Improved Internet Download 201 Using COM Objects 202 Which COM Objects Are Available? 203 How Do You Use COM Objects? 203 Summary 204 Conditions 206 Formulating Conditions 206 Carrying Out a Comparison 207 "Reversing" Comparisons 209 Combining Comparisons 209 Comparisons with Arrays and Collections 210 Verifying Whether an Array Contains a Particular Element 211 Where-Object 211 Filtering Results in the Pipeline 211 Formulating a Condition 213 Using Alias 214 If-ElseIf-Else 214 Switch 216 Testing Range of Values 217 No Applicable Condition 218 Several Applicable Conditions 218 Using String Comparisons 219 Case Sensitivity 220 Wildcard Characters 220 Regular Expressions 221 Processing Several Values Simultaneously 221 Summary 223 Loops 224 ForEach-Object 224 Evaluating Pipeline Objects Separately 224 Integrating Conditions 225 Invoking Methods 227 Foreach 228 Do and While 232 Continuation and Abort Conditions 232 Using Variables as Continuation Criteria 233 Endless Loops without Continuation Criteria 234 For 234 For Loops: Just Special Types of the While Loop 235 Unusual Uses for the For Loop 236 Switch 237 Processing File Contents Line by Line 238 Exiting Loops Early 238 Continue: Skipping Loop Cycles 240 Nested Loops and Labels 240 Summary 242 Functions 243 Creating New Functions 244 First Example: Shorthand Functions 244 Second Example: Combining Several Steps 245 Comfortably Entering Functions of Several Lines 245 Reducing a Function to a Single Line 246 Using Text Editors 246 Understanding NextFreeDrive 246 Processing and Modifying Functions 247 Removing Functions 248 Passing Arguments to Functions 248 $args: Arbitrary Arguments 249 Setting Parameters 252 Arguments Having Predefined Default Values 255 Using Strongly Typed Arguments 256 Only Numbers Allowed 256 Date Required 258 "Switch" Parameter Is Like a Switch 259 Specifying Return Values of a Function 260 One or More Return Values? 260 The Return Statement 261 Accessing Return Values 263 Excluding Output from the Function Result 264 Excluding Text Output from the Result 264 Using Debugging Reports 265 Suppressing Error Messages 266 Inspecting Available Functions 267 Prompt: A Better Prompt 269 Outputting Information Text at Any Location 270 Using the Windows Title Bar 270 Administrator Warning 271 Clear-Host: Deleting the Screen Buffer 272 Predefined Functions Once Again: A:, B:, C: 273 Functions, Filters and the Pipeline 274 The Slow Sequential Mode: $input 274 Filter: Rapid Streaming Mode 275 Developing Genuine Pipeline Functions 276 Summary 277 Scripts 279 Writing and Starting PowerShell Scripts 280 Using Redirection to Create Scripts 280 Creating Scripts with an Editor 281 Starting Scripts 281 Execution restrictions 281 Invoking Scripts like Commands 283 Passing Arguments to Scripts 285 $args Returns All Arguments 285 $args is an Array 285 Accessing Separate Arguments in $args 286 Using Parameters in Scripts 286 Validating Parameters 288 Scopes: Ranges of Validity in Scripts 289 #requires: Script Requirements 291 Making Scripts Understandable 292 Using Functions in Scripts 292 Separating Scripts into Work Scripts and Libraries 294 Library Scripts Central Directory 295 Creating Pipeline Scripts 296 Slow Sequential Mode 296 Quicker Streaming Mode 297 Writing Pipeline Results 298 Profile: Autostart Scripts 299 Four Different Profile Scripts 299 Creating Your Own Profile 300 Create a Global Profile for All Users 301 Digital Signatures for Your Scripts 302 Finding an Appropriate Certificate 302 Creating a New Certificate 303 Creating Self-Signed Certificates 304 Examining the Code-Signing Certificate 304 Declaring a Certificate "Trusted" 305 Signing PowerShell Scripts 308 Using the First Available Certificate 308 Recursively Signing All PowerShell Scripts 309 Selecting Certificates Using the Dialog Box 309 Validating Signed PowerShell Scripts 310 Manual Validation 311 Automatic Validation 313 Building a Miniature PKI 315 Creating a Root Certificate 315 Creating Staff Certificates 316 Creating a Backup 317 Installing Enterprise-Wide Root Certificates 317 Summary 318 Finding and Avoiding Errors 320 "What-if" Scenarios 321 Dry Runs: Simulating Operations 321 Stepped Confirmation: Separate Queries 322 Automatic Confirmation of Dangerous Actions 323 Defining Fault tolerance 324 Recognizing and Responding to Errors 326 Error Status in $? 326 Using Traps 326 Traps Require Unhandled Exceptions 327 Using Break and Continue to Determine What Happens after an Error 328 Finding Out Error Details 328 Error Records: Error Details 329 Error Record by Redirection 330 Error Record(s) Through the -ErrorVariable Parameter 332 Error Records Through $Error 333 Error Record Through Traps 333 Understanding Exceptions 333 Handling Particular Exceptions 334 Throwing Your Own Exceptions 335 Catching Errors in Functions and Scripts 336 Stepping Through Code: Breakpoints 339 Tracing: Displaying Executed Statements 343 Stepping: Executing Code Step-by-Step 344 Summary 344 Command Discovery and Scriptblocks 346 Command Discovery 347 The Call Operator "&" 349 The Call Operator Only Accepts Single Commands 349 The Call Operator Executes CommandInfo Objects 350 Identically Named Commands: Which is Running? 351 Using Scriptblocks 354 Executing Entire Instruction Lines 354 Invoke-Expression 354 Pipeline: ForEach-Object 355 Loops: If and For 355 Functions Are Named "Scriptblocks" 356 Building Scriptblocks 357 Passing Arguments to Scriptblocks 357 Begin, Process, End Pipeline Blocks 358 Validity of Variables 359 ExecutionContext 360 InvokeCommand 360 Resolving Variables 360 Creating Scriptblocks 361 Executing Instruction Lines 361 SessionState 362 Managing Variables 362 Managing Drives 362 Path Specifications 363 Summary 364 Text and Regular Expressions 365 Defining Text 366 Special Characters in Text 366 Resolving Variables 366 Inserting Special Characters 367 "Here-Strings": Acquiring Text of Several Lines 368 Communicating with the User 368 Querying User Name and Password 369 Using Special Text Commands 370 String Operators 371 Formatting String 373 Setting Numeric Formats 373 Outputting Values in Tabular Form: Fixed Width 379 String Object Methods 379 Analyzing Methods: Split() as Example 382 Using String Class Commands 384 Join(): Changing Arrays to Text 385 Concat(): Assembling a String Out of Several Parts 385 Simple Pattern Recognition 386 Regular Expressions 387 Describing Patterns 388 Quantifiers 390 Anchors 390 Recognizing IP Addresses 391 Validating E-Mail Addresses 392 Simultaneous Searches for Different Terms 393 Case Sensitivity 394 Finding Information in Text 396 Searching for Several Keywords 398 Forming Groups 400 Further Use of Sub-Expressions 401 Greedy or Lazy? Detailed or Concise Results... 403 Finding String Segments 405 Replacing a String 405 Using Back References 405 Putting Characters First at Line Beginnings 406 Removing Superfluous White Space 408 Finding and Removing Doubled Words 408 Summary 408 XML 410 XML Structure 410 Loading and Processing XML Files 412 Accessing Single Nodes and Modifying Data 412 Using SelectNodes() to Choose Nodes 413 Accessing Attributes 414 Adding New Nodes 414 Exploring the Extended Type System 415 The XML Data of the Extended Type System 415 Finding Predefined Views 416 The File System 421 Accessing Files and Directories 423 Listing Directory Contents 424 Recursively Searching the Entire File System 424 Filter and Exclusion Criterion 425 Getting File and Directory Contents 426 Passing Files to Cmdlets, Functions, or Scripts 428 Navigating the File System 430 Relative and Absolute Paths 430 Converting Relative Paths into Absolute Paths 431 Saving Directory Locations 433 Finding Special Directories 434 Constructing Paths 437 Working with Files and Directories 439 Creating New Directories 439 Creating New Files 440 Creating New Drives 441 Reading the Contents of Text Files 442 Processing Comma-Separated Lists 443 Parsing Text Contents and Extracting Information 444 Reading Binary Contents 446 Moving and Copying Files and Directories 448 Renaming Files and Directories 449 Numerous Renames 449 Changing File Extensions 449 Sorting Out File Names 450 Deleting Files and Directories 451 Deleting Directory Contents 452 Deleting Directories and Their Contents 452 Managing Access Permissions 453 Checking Effective Security Settings 454 Establishing the Identity of the Owner 454 Listing Access Permissions 454 Creating New Permissions 455 "Cloning" Permissions 456 Using SDDL to Set Permissions 457 Manually Creating New Permissions 458 The Registry 463 "Provider": Locations Outside the File System 465 Available Providers 465 Creating Drives 467 Searching the Registry 469 Recursive Search 469 Individual Registry Keys 470 How PowerShell Addresses Registry Keys 471 Values of Keys 472 Subkey of a Key 474 Creating and Deleting Keys and Values 475 Deleting Keys with Contents 476 Setting, Changing, and Deleting Values of Keys 477 Adding New Values 477 Reading Values 479 Deleting Values 480 Default Entry 480 Example: Extending the Context Menu 481 Executing and Editing PowerShell Scripts 482 Permissions in the Registry 483 Taking Ownership 483 Setting New Access Permissions 484 Removing an Access Rule 484 Controlling Access to Subkeys 485 Revealing Inheritance 486 Controlling Your Own Inheritance 487 Processes, Services, Event Logs 489 Processes 489 Starting Processes 489 Monitoring Processes 490 Filtering and Clearly Displaying Processes 492 Counting Processes 493 Accessing Process Objects 494 Stopping Processes 494 Services 495 Listing Services 495 Starting, Stopping, Suspending, Resuming Services 496 Event Log 497 Writing Entries to the Event Log 499 WMI: Windows Management Instrumentation 501 WMI Classes and Instances 501 Instances of a Class 502 Displaying All Properties 503 Filtering Out PowerShell Properties 504 Selecting Particular Instances 504 Directly Accessing Instances 505 Modifying Properties 507 Viewing Class Descriptions 507 Invoking WMI Methods 508 Instance-Based Methods 508 Listing Methods 510 Static Methods 510 Help with Classes and Methods 512 WMI Events 513 Remote Access and Namespaces 514 Accessing WMI Objects on another Computer 514 Namespaces: WMI Extensions 515 WMI and the Extended Type System 516 Converting the WMI Date Format 517 Adding On a Type Converter 517 User Management 521 Connecting to a Domain 521 Logging On Under Other User Names 522 Accessing a Container 525 Listing Container Contents 525 Accessing Individual Users or Groups 526 Using Filters and the Pipeline 526 Directly Accessing Elements 527 Obtaining Elements from a Container 528 Searching for Elements 529 Accessing Elements Using GUID 533 Reading and Modifying Properties 533 Just What Properties Are There? 534 Practical Approach: Look 534 Theoretical Approach: Much More Thorough 536 Reading Properties 539 Modifying Properties 540 Deleting Properties 542 The Schema of Domains 544 Setting Properties Having Several Values 546 Invoking Methods 546 Changing Passwords 548 Controlling Group Memberships 549 In Which Groups Is a User a Member? 550 Which Users Are Members of a Group? 550 Adding Users to a Group 550 Creating New Objects 551 Creating New Organizational Units 551 Create New Groups 551 Creating New Users 552 Your Own Cmdlets and Extensions 553 Compiling Your Own .NET Expansions 553 Extension for the Clipboard 554 In-Memory Compiling 555 DLL Compilation 556 Building Your Own Cmdlets 556 How Cmdlets Are Structured 557 Step 1: Compiling the Snap-In 559 Step 2: Registering Snap-Ins 560 Step 3: Loading Snap-Ins 561 The Structure of Cmdlets 562 The Snap-In 563 The Cmdlet 563 Begin, Process, End 564 About Idera's PowerShell Plus 565 Sponsors 566 Idera 566 PowerShell.com 566 Compellent 566 /n software 566 Additional Resources 567 BBS Technologies, 2009. — 517 p. Free ‘Mastering PowerShell’ eBook Now Available on PowerShell.com PowerShell Authority Helps Both Novices and Experts Get More Out of the Scripting Language HOUSTON – July 14, 2009 – Dr. Tobias Weltner, a leading PowerShell expert and Microsoft PowerShell MVP, today announced that his book, Mastering PowerShell, is now available as a free eBook online and as a PDF download on www.PowerShell.com. Sponsored by Idera, the providers of PowerShell Plus, the leading IDE for PowerShell, Mastering PowerShell consists of 20 chapters focused on a wealth of topics ranging from an introduction to the PowerShell console, to how to write custom scripts, to creating your own cmdlets and extensions. I have condensed my practical experience into an easy-to-read eBook that is geared to both administrators newly transitioning to PowerShell and more advanced users looking to enhance their expertise, said Dr. Weltner. The eBook adds to the large library of informational content on PowerShell.com that so many administrators have found useful in their daily application of PowerShell. PowerShell.com serves as a primary resource to help increase the adoption and use of PowerShell by providing learning materials, expert guidance, news, forums and libraries for sharing best practices. The site is designed to serve as a place for PowerShell people to congregate, communicate, collaborate and construct new ideas. Pricing and Availability The Mastering PowerShell eBook is available for free now as a PDF and to read online at http://powershell.com/cs/blogs/ebook/ About Dr. Tobias Weltner As a graduated M.D. , Dr. Weltner now specializes in Microsoft technology and automation techniques. He is a software architect, trainer, author of more than 80 books covering topics such as script automation and PowerShell, and the creator of PowerShell.com. In July 2008, Dr. Weltner was awarded the prestigious Microsoft MVP Award for the fifth time since 2002 for his contributions to the Microsoft community.
دانلود کتاب Mastering PowerShell