Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying PowerShell 7 Workshop
  • Table Of Contents Toc
  • Feedback & Rating feedback
PowerShell 7 Workshop

PowerShell 7 Workshop

By : Nick Parlow
3.7 (3)
close
close
PowerShell 7 Workshop

PowerShell 7 Workshop

3.7 (3)
By: Nick Parlow

Overview of this book

Discover the capabilities of PowerShell 7 for your everyday tasks with this carefully paced tutorial that will help you master this versatile programming language. The first set of chapters will show you where to find and how to install the latest version of PowerShell, providing insights into the distinctive features that set PowerShell apart from other languages. You’ll then learn essential programming concepts such as variables and control flow, progressing to their applications. As you advance, you’ll work with files and APIs, writing scripts, functions, and modules. You’ll also gain proficiency in securing your PowerShell environment before venturing into different operating systems. Enriched with detailed practical examples tailored for Windows, Linux, macOS, and Raspberry Pi, each chapter weaves real-world scenarios to ignite your imagination and cement the principles you learn. You’ll be able to reinforce your understanding through self-assessment questions and delve deeper into the principles using comprehensive reading lists. By the end of this book, you’ll have the confidence to use PowerShell for physical computing and writing scripts for Windows administration.
Table of Contents (23 chapters)
close
close
1
Part 1: PowerShell Fundamentals
9
Part 2: Scripting and Toolmaking
15
Part 3: Using PowerShell

What is PowerShell 7 used for?

PowerShell is for getting things done quickly. It’s for when you need a relatively short piece of code for something that you can reuse and repurpose easily to do something else. It’s for when you don’t want to spend months learning a language, then more months writing thousands of lines of code. The language can be used in at least four ways:

  • You can input single lines of code in the shell, as you would at the Windows Command Prompt or the Linux Terminal. This is great if you need to check a value, accomplish a single task such as rebooting a remote computer, or grab a log file.
  • You can write a script, such as a Bash script in Linux or a batch file for Windows, that accomplishes multiple subtasks, such as gathering event logs and performance information from several machines and compiling them into a single HTML report.
  • If you write a lot of scripts or need to accomplish something more complex, you can use PowerShell as a procedural programming language with multiple packaged scripts that each describe a single function and are called by a master script.
  • You can use it as an object-oriented programming language and package a whole application that can be redistributed and run by anyone with PowerShell installed.

We’ll be focusing on scripts and procedural programming in this book, as that is how most people use PowerShell. These are very similar; the difference is that in a script, you are using cmdlets that have been written for you, but in procedural programming, you are creating your own cmdlets, either from pre-existing cmdlets or by using the system programming language C#.

Scripting languages versus system programming languages

The PowerShell language is a scripting language. It’s for gluing other applications together quickly and easily – sort of a coding version of Lego. It relies on an underlying interpreter: the PowerShell program. Without PowerShell installed, a PowerShell script can’t run. This is quite similar to other interpreted languages, such as Python, and sits in contrast to system programming languages, such as C or C++, which are compiled into executable files. When you compile a C++ program, it can theoretically run on any compatible machine. There are other differences as well – here are some of the main ones:

  • Interpreted languages are less efficient than compiled languages because each line has to be interpreted before it can run. This means they are slower than compiled programs. There are programming tricks you can use to speed things up, but performing a task in an interpreted language will pretty much always be slower than doing it in a compiled language.
  • Interpreted languages are more efficient than compiled languages in development. They accomplish the same tasks with far fewer lines of code. This means that writing them, debugging them, and reusing them is much quicker. They are also much easier to learn.
  • Interpreted languages can run on multiple architectures. As we’ll see in this book, code written in PowerShell can run on Windows, Linux, or macOS, with minimal tweaking. A program written in C++ for Windows can only run on Windows, or a machine with Windows emulation. It would need to be rewritten and recompiled for a different platform.
  • Interpreted languages produce collaborative reusable programs. With PowerShell (or Python), you produce code that is readable and editable by humans. With a compiled language, you produce a binary file that cannot easily be decompiled into source code for reuse. This means other people can reuse your code for their own purposes. Platforms such as GitHub can be used to distribute your code, other people can contribute to it, improve it, reuse it for their programs, and act in a generally communitarian fashion.

It boils down to this: if you want to write a super-fast first-person shooter game with spectacular graphics, then PowerShell is probably not the language for you. If you want to automate some tasks, simple or complex, then PowerShell is a good choice.

bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY