Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PowerShell 7 Workshop

You're reading from   PowerShell 7 Workshop Learn how to program with PowerShell 7 on Windows, Linux, and the Raspberry Pi

Arrow left icon
Product type Paperback
Published in Feb 2024
Publisher Packt
ISBN-13 9781801812986
Length 468 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Nick Parlow Nick Parlow
Author Profile Icon Nick Parlow
Nick Parlow
Arrow right icon
View More author details
Toc

Table of Contents (23) Chapters Close

Preface 1. Part 1: PowerShell Fundamentals
2. Chapter 1: Introduction to PowerShell 7 – What It Is and How to Get It FREE CHAPTER 3. Chapter 2: Exploring PowerShell Cmdlets and Syntax 4. Chapter 3: The PowerShell Pipeline – How to String Cmdlets Together 5. Chapter 4: PowerShell Variables and Data Structures 6. Chapter 5: PowerShell Control Flow – Conditionals and Loops 7. Chapter 6: PowerShell and Files – Reading, Writing, and Manipulating Data 8. Chapter 7: PowerShell and the Web – HTTP, REST, and JSON 9. Part 2: Scripting and Toolmaking
10. Chapter 8: Writing Our First Script – Turning Simple Cmdlets into Reusable Code 11. Chapter 9: Don’t Repeat Yourself – Functions and Scriptblocks 12. Chapter 10: Error Handling – Oh No! It’s Gone Wrong! 13. Chapter 11: Creating Our First Module 14. Chapter 12: Securing PowerShell 15. Part 3: Using PowerShell
16. Chapter 13: Working with PowerShell 7 and Windows 17. Chapter 14: PowerShell 7 for Linux and macOS 18. Chapter 15: PowerShell 7 and the Raspberry Pi 19. Chapter 16: Working with PowerShell and .NET 20. Answers to Activities and Exercises 21. Index 22. Other Books You May Enjoy

What this book covers

Chapter 1, Introduction to PowerShell – What It Is and How to Get It, explains what PowerShell 7 is, describes its uses, and how it differs from Windows PowerShell. It describes how to get it, how to install it, and how to run it, explaining the difference between User and Administrator mode. It describes how to run cmdlets and how to get help in PowerShell.

Chapter 2, Exploring PowerShell Cmdlets and Syntax, focuses on how PowerShell cmdlets work, approved verbs, parameters, how to find new cmdlets with the PowerShell Gallery and elsewhere on the internet, and finally, how to work interactively with PowerShell.

Chapter 3, The PowerShell Pipeline – How to String Cmdlets Together, covers how the PowerShell pipeline is one of the most important concepts in PowerShell and is quite different from how pipelines work in Bash and the Command Prompt. This chapter will show you how to successfully chain cmdlets together in a pipeline to produce useful outcomes. It will talk about filtering, output, how the pipeline works, and why it sometimes doesn’t!

Chapter 4, PowerShell Variables and Data Structures, is an introduction to variables and the different types they may be, integers, floats, and how these are all objects. We’ll explore the object concept and why it is important. We’ll look at data structures as collections of objects, then arrays and hash tables, and finish with splatting.

Chapter 5, PowerShell Control Flow – Conditionals and Loops, covers conditional flow (*IF* this, *THEN* that) and loops, including for, each, and while loops. Often, you won’t want to process cmdlets in a linear fashion – you’ll want to only do something if another thing is true or do something for all the objects in a pipeline. Control flow is how we do this. This chapter will also move us on from running interactive cmdlets to writing very simple scripts in VS Code.

Chapter 6, PowerShell and Files – Reading, Writing, and Manipulating Data, shows you how to take data from common file types such as CSV and TXT files and manipulate it, as well as how to send your output to files, alleviating the tedium of having to read output off a screen and typing loads of it in. We’ll also cover how to output to HTML, which is great for creating formatted reports and live data in web-hosted dashboards.

Chapter 7, PowerShell and the Web – HTTP, REST, and JSON, explores PowerShell and the web. Files are all very well, but a lot of cloud administration requires the manipulation of data from the internet; to do this, we’ll need to be able to manipulate the most common internet data type, JSON. We’ll also want to manipulate cloud services, for which we will need to be able to use REST API calls. This chapter will walk through that.

Chapter 8, Writing Our First Script – Turning Simple Cmdlets into Reusable Code, focuses on how we can turn lines of code into a script that we can save and run over and over again. We’ve covered how to write a few lines of code in an IDE. How do we turn that into something that we would want to run repeatedly, and make it useful for other people to run?

Chapter 9, Don’t Repeat Yourself – Functions and Scriptblocks, introduces you to functions in PowerShell as well as script blocks and lambdas. When writing a script, we will frequently find ourselves running the same few lines of code. Turning them into functions within the script means we only need to write it once, just calling it every time we need it.

Chapter 10, Error Handling – Oh No! It’s Gone Wrong!, covers the two main types of errors that we’re likely to encounter – problems that our code encounters and problems with our code. In the first part of the chapter, we’ll define what an error is, how we can set PowerShell up to handle errors gracefully, and how we can make sense of them. In the second part, we’ll look at how we can identify problems with our code and use VS Code for debugging.

Chapter 11, Creating Our First Module, examines how to turn functions and scripts into a module that can be reused, easily distributed, and incorporated into other scripts. Now we have a script, containing a set of functions, the next step is to turn that into a tool that others can use for themselves.

Chapter 12, Securing PowerShell, delves into how to secure our PowerShell scripts and modules and run them in a secure fashion. PowerShell is a very powerful tool, and with great power comes great responsibility. The chapter will cover script execution policies, code signing, AppLocker, and some of the other security features.

Chapter 13, Working with PowerShell 7 and Windows, explores how to use PowerShell 7 on Windows, when we will need to use PowerShell 5.1, how to interact with remote machines using WinRM, how to manage machines with CIM, and basic interaction with Windows features such as storage. PowerShell originated on Windows, and PowerShell 7 is intended to eventually replace Windows PowerShell, but we’re not there yet.

Chapter 14, PowerShell 7 for Linux and macOS, explains how to install PowerShell on Linux, how it differs from running PowerShell on Windows, and how to use VS Code on Linux. It explains remoting with OpenSSH, how to run scripts, and some common administration tasks. It finishes with a section on installing and running PowerShell and VS Code on macOS.

Chapter 15, PowerShell 7 and the Raspberry Pi, examines how to get started with PowerShell on Raspberry Pi, allowing us to do home automation, maker projects and more. It covers installing PowerShell and VS Code, connecting to the Pi, and running scripts. Raspberry Pi is everybody’s favorite single board computer, and we can transfer our PowerShell skills to our Pi stable.

Chapter 16, Working with PowerShell and .NET, delves into .NET, which is the developer platform that PowerShell 7 is built on; it’s free, open source, and works well with VS Code. There are lots of things we can’t do easily with PowerShell alone, but we can leverage .NET to achieve them. Familiarity with .NET is an essential skill for every advanced PowerShell coder, and this chapter will help you get there.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime