Learn the basic tools and commands to write scripts in PowerShell 7. This hands-on guide is designed to get you up and running on PowerShell quickly - introducing interactive menus, reading and writing files, and creating code that talks over the network to other scripts, with mini games to facilitate learning. PowerShell for Beginners starts with an introduction to PowerShell and its components. It further discusses the various tools and commands required for writing scripts in PowerShell 7, with learning reinforced by writing mini games. You will learn how to use variables and conditional statements for writing scripts followed by loops and arrays. You will then work with functions and classes in PowerShell. Moving forward, you will go through the PowerShell Console, customizing the title and text colors. Along the way you will see how to read a key press and make sound in PowerShell. The final sections cover game engine layout, how to build a title screen, and implementing the game design using code flow, title screens, levels, and much more. After reading the book you will be able to begin working with PowerShell 7 scripts and understand how to use its tools and commands effectively. What You Will Learn Use Microsoft Visual Studio Code to develop scripts Understand variables, loops and conditional statements in PowerShell Work with scripts to develop a game Discover and use ASCII art generators Comprehend game objects and code Create client-server scripts that communicate over a network Read and write to files Capture input from the keyboard Make PowerShell speak words to help the visually impaired Create text-based adventure games Who This Book Is For Software developers who want to start working with PowerShell scripts. Table of Contents 5 About the Author 11 About the Technical Reviewer 12 Introduction 13 Chapter 1: Introduction 15 Terminology 15 Variables 16 Cmdlets 16 Scripts 16 Functions 17 Classes 17 Modules 17 Objects 17 Pipeline 18 .Net Framework 18 History 18 The Future 19 Required Tools 19 Let’s Get Started! 20 Chapter 2: Beginners’ Guide to PowerShell and Visual Studio Code 21 PowerShell 7 21 Install PowerShell 7 21 Get Help Running Cmdlets 25 How to Run Scripts 28 Visual Studio Code 30 Install Visual Studio Code 30 Open a New Project Folder 32 Creating a New Script File 34 PowerShell Visual Studio Code Extension 35 Saving Scripts 36 Running Scripts 36 Running Your First Script 37 Debugging Your Scripts 38 Running Part of a Script 43 Running Scripts or Cmdlets Directly from the PowerShell Terminal Window 44 Adding Comments to Your Code 45 Comment-Based Help 45 Single-Line Comments 46 Multiline Comments 46 Conclusion 46 Chapter 3: Variables 47 What Are Variables? 49 Variable Types 49 Defining Variables 50 Updating Variables 51 Accessing Variables 52 Variable Scope 53 Global Variables 53 Conclusion 54 Chapter 4: Conditional Statements 55 if Statements 60 Comparison Operators 65 Switch Statement 67 Conclusion 69 Chapter 5: Loops 70 For Loops 71 While Loops 73 Do While Loops 74 Foreach Loops 75 ForEach-Object Loops 76 Conclusion 77 Chapter 6: Arrays 78 Initializing an Array 80 Array Properties and Methods 82 Accessing Values in an Array 83 Removing Values from an Array 85 Conclusion 87 Chapter 7: Functions 88 Creating a Function 88 Passing Parameters 90 Returning Objects 91 Conclusion 94 Chapter 8: Classes 95 Creating Your First Class 96 Properties 97 Constructors 98 Methods 98 Passing Parameters 100 Returning Objects 102 Conclusion 103 Chapter 9: Customizing the Console 104 Customizing the Title and Text Colors 104 Resizing the Console 106 Conclusion 107 Chapter 10: User Input 108 Reading a Key Press 108 Read a Line of Text 110 Conclusion 111 Chapter 11: Dragon Slayer 112 Code Design 112 Defining the Functions 114 Creating the Title Screen 117 Script Variables 119 Let’s Put It All Together 119 Conclusion 130 Chapter 12: Getting Colorful 131 Changing Font Color 131 Changing Background Color 132 Changing the Default Console Colors 134 Conclusion 136 Chapter 13: ASCII Table 137 Displaying Shapes and Symbols 137 Output an ASCII Table in HTML 139 Building a Menu Box 141 Conclusion 142 Chapter 14: Cursor Control 143 Moving the Cursor 143 Moving a Character Around the Screen 146 Keeping Within the Boundaries 146 Reducing the Flicker 147 Bring It All Together 148 Conclusion 151 Chapter 15: Background Processing 152 Starting a Job 152 Managing a Specific Job and Passing Multiple Parameters 154 Receiving the Results of a Job 155 Stopping Jobs 157 Removing Jobs 158 Conclusion 159 Chapter 16: Networking 160 Basic Networking Introduction 160 Creating a Basic Server App 161 Creating the Listener 161 Reading New Messages 162 Creating a Basic Client App 163 Creating the TCP Client 163 Sending Messages 164 Putting It All Together 164 Conclusion 166 Chapter 17: Working with Files 167 Checking If a File Exists 167 Reading Files 169 Writing to Files 170 Add-Content 171 Set-Content 173 Conclusion 173 Chapter 18: Sound 174 Beep, Beep 174 Playing wav Files 175 Making PowerShell Speak 175 Conclusion 177 Chapter 19: Game Engine 178 Game Engine Layout 178 The Setup Phase 179 The Title Screen 179 The Game Loop 179 The Game Over Screen 180 The Setup Phase 180 Set Up the Display to the Required Size 180 Load a Game Configuration File 181 Load a Title Screen from a Text File 184 Load Each Object and Character from Text Files 186 Solving the Screen Flicker Problem 189 The Game Loop 190 Conclusion 193 Chapter 20: Creating Game Artwork 194 Building a Title Screen 194 ASCII Art Generators 195 ASCII Text 196 ASCII Images 197 Conclusion 199 Chapter 21: PowerBomber 200 Game Design 200 Code Flow 200 Setup 203 Title Screen 205 Levels 206 Game Objects 210 Standard Wall Block 211 Explodable Wall Block 211 Bombs 212 Code 217 Conclusion 234 Index 235