Master PowerShell Tricks Volume 3
Master PowerShell Tricks Volume 3
About the Book
“PowerShell is awesome.” I’ve lost track of how many times I’ve heard this phrase and I never get tired of hearing it..
I remember the launch of Windows Server 2012 like it was yesterday. It was a major release with innovation across the board in Hyper-V, Storage, Networking, Scale and Performance. Underlying all of this innovation was one unifying investment designed to make it easier for you to harness these technologies: PowerShell. With over 2500 PowerShell commandlets built-in, rich automation was now in everyone’s hands. Over the years, we listened as you used PowerShell for everything from simple repeatable tasks to complex deployments of servers, software and services where PowerShell removed human error.
A few releases later, we’ve added over a thousand new commandlets, Desired State Configuration (DSC), and Just Enough Administration (JEA) making PowerShell an indispensable and valuable skill for every résumé. If you haven’t learned PowerShell yet, there’s no time like the present. (Spoiler alert: It’s fun too…) The authors are PowerShell experts and MVPs who teach and coach in the Microsoft community with years of experience. In addition, they have used their learnings in the community to provide feedback to the PowerShell team and help influence the product direction. Whether you or a seasoned user or a PowerShell newbie, you can’t ever know too many PowerShell Tricks.
Windows Server/Hybrid Cloud
Foreword by: Jeff Woolsey iii
From Dave iv
About the Authors v
Dave Kawula - MVP v
Thomas Rayner - MVP vi
Allan Rafuse – MVP vii
Will Anderson – MVP viii
Mick Pletcher – MVP ix
Technical Editors x
Cristal Kawula – MVP x
Emile Cabot - MVP xi
Cary Sun – CCIE #4531 (Future Microsoft MVP) xii
North American MVPDays Community Roadshow 20
Sample Files 21
Additional Resources 21
Chapter 1 23
Using PowerShell to Download Drivers via FTP 23
Chapter 2 27
Using PowerShell to Download Videos from Channel 9 27
Chapter 3 35
Snapshot Management of VMware with PowerShell 35
Snapshot Management 35
Password Issues 36
Report Output 36
The Code (VMWare Example) 37
Chapter 4 42
Setting SQL Server Memory Allocation (Maximum and Minimum) 42
Retrieving the Physical Memory 42
Determine SQL Server Maximum Memory 43
Reconfigure SQL Server Memory Allocation 44
Making IT Work 46
Chapter 5 47
Using PowerShell to Add a Direct Member to an SCCM Collection 47
Chapter 6 49
Using PowerShell to Manage the Datadog Cloud Service 49
Example Snippets 50
Searching for Events 53
Chapter 7 55
Using PowerShell to Update the .Default and All User Profiles Registry 55
Enumerate all the existing user profiles 55
Add the .DEFAULT user profile to the list of existing profiles 56
Iterate through all the profiles 56
Manipulate the users’ registry 57
If the Profile hive was loaded by script, unload it 58
Chapter 8 60
Working with PowerShell Active Directory Module as a Non-Privileged User 60
Chapter 9 62
Using PowerShell to Split a String Without Losing the Character You Split On 62
Chapter 10 65
What's the difference between -split and .split() in PowerShell? 65
Chapter 11 68
PowerShell Rules for Format-Table and Format-List 68
Chapter 12 70
The Difference Between Get-Member and .GetType() in PowerShell 70
Chapter 13 73
Dynamically Create Preset Tests for PowerShell 73
Chapter 14 77
Piping PowerShell Output into Bash 77
Chapter 15 78
How to List All the Shares on a Server using PowerShell 78
Chapter 16 81
Get a ServiceNow User Using PowerShell 81
Chapter 17 83
Add a Work Note to a ServiceNow Incident with PowerShell 83
Chapter 18 86
Use PowerShell to see how many items are in a Directory 86
Chapter 19 87
Add a Column to a CSV using PowerShell 87
Chapter 20 90
Diagnosing slow PowerShell Load Times 90
Chapter 21 91
Use Test-NetConnection in PowerShell to see if a Port is Open 91
Chapter 22 92
Use PowerShell to find out How Long it is until Christmas 92
Chapter 23 94
Use PowerShell to Figure out “What day of the week” x number of days from now 94
Chapter 24 96
Using Get-Member to Explore Objects 96
Chapter 25 99
Using Select-Object to Explore Objects 99
Chapter 26 104
Can PowerShell Parameters Belong to Multiple Sets? 104
Chapter 27 106
Opening an Exchange Online Protection Shell 106
Chapter 28 108
Import Active Directory Module into Windows PE 108
Chapter 29 120
Using PowerShell to report on Windows Updates installed during MDT OSD Build 120
Chapter 30 130
Report on Mapped Drives to understand Cryptolocker Vulnerabilities with SCCM and PowerShell 130
Chapter 31 141
Set Windows Features and Verify with PowerShell 141
Chapter 32 148
Uninstall an Application by Name with PowerShell 148
Chapter 33 151
Azure Automatic Account Creation and Adding Modules using PowerShell 151
Creating the Azure Automation Account 151
Creating a Blob Container in AzureRM 153
Upload a Blob Container 155
Chapter 34 157
Configuring Azure Automation Runbooks and Understanding Webhook Data using PowerShell 157
Creating the Runbook Script 158
Publish the Runbook 160
Create an Alert 161
Validating our Data 165
Chapter 35 169
Utilizing Webhook Data in Functions and Validate Results using PowerShell 169
Building on Webhook Data 169
Chapter 36 180
Adding Configuration to your Azure Automation Account using Azure DSC 180
Push vs. Pull 181
Pros and Cons to Each 182
Things to Consider 183
Upload the Configuration 186
Compile the Configuration 189
Chapter 37 194
Onboarding Automation DSC Endpoints and Reporting 194
Register the Virtual Machine 195
Apply a Configuration 197
Azure Automation DSC Reports 199
Connecting to Log Analytics 201
Chapter 38 206
Publishing Configurations and Pushing them with Azure DSC 206
Publish the Configuration 206
Install the VM Extensions 208
Chapter 39 212
Testing RDMA Connectivity with PowerShell 212
Chapter 40 223
Storage Spaces Direct Network Reporting HTML Script for Mellanox Adapters via PowerShell 223
Chapter 41 227
Using PowerShell and DSC to build out an RDSH Farm from Scratch 227
Chapter 42 248
Join us at MVPDays and meet great MVP’s like this in person 248
Live Presentations 248
Video Training 248
Live Instructor-led Classes 249
Consulting Services 249
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Algebra-Driven DesignSandy Maguire
A how-to field guide on building leak-free abstractions and algebraically designing real-world applications.
Production HaskellMatt Parsons
Are you excited about Haskell, but don't know where to begin? Are you thrilled by the technical advantages, but worried about the unknown pitfalls? This book has you covered.
The Hundred-Page Machine Learning BookAndriy Burkov
Everything you really need to know in Machine Learning in a hundred pages.
Ansible for DevOpsJeff Geerling
Ansible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Machine Learning EngineeringAndriy Burkov
"If you intend to use machine learning to solve business problems at scale, I'm delighted you got your hands on this book."
—Cassie Kozyrkov, Chief Decision Scientist at Google
"Foundational work about the reality of building machine learning models in production."
—Karolis Urbonas, Head of Machine Learning and Science at Amazon
Cloud StrategyGregor Hohpe
“Strategy is the difference between making a wish and making it come true.” A successful migration to the cloud shouldn’t be driven by wishes, but guided by a sound strategy, frameworks, and decision models. This book tells you how—without becoming superficial nor getting lost in technology and product details.
CCIE Service Provider Version 4 Written and Lab Exam Comprehensive GuideNicholas Russo
The service provider landscape has changed rapidly over the past several years. Networking vendors are continuing to propose new standards, techniques, and procedures for overcoming new challenges while concurrently reducing costs and delivering new services. Cisco has recently updated the CCIE Service Provider track to reflect these changes; this book represents the author's personal journey in achieving that certification.
CCIE SP v4.1 - WorkbookŁukasz Bromirski, Piotr Jablonski, and Nicholas Russo
Are you striving to prepare to and pass CCIE SP lab exam? Take the opportunity and get this workbook! With the attached initial cfg files you will prepare yourself for the CCIE SP exam as well as learn SP technologies applicable to all kinds of today modern networks! This workbook covers blueprint topics and provides challenging examples.
C++ Best PracticesJason Turner
Level up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Introducing EventStormingAlberto Brandolini
The deepest tutorial and explanation about EventStorming, straight from the inventor.
The Node.js Bundle
3 BooksThis bundle combines three bestselling Leanpub Node.js books into a package that gives you everything you need to get started with developing Node.js applications at an unbeatable price.
The Tester's Library
8 BooksThe Tester's Library consists of eight five-star books that every software tester should read and re-read. As bound books, this collection would cost over $200. Even as e-books, their price would exceed $80, but in this bundle, their cost is only $49.99. Here are the books, and why they should be in your library: Perfect Software and Other...
11 BooksIn this bundle, you will find 10 different agile books. They are about different aspects of being agile. - finding a job - doing coding dojo's - Retrospectives - Personal kanban - a non-typical coaching book and even a book that gives you an insight in the lives of some agile people.
WTFlop 6M + HU - Beta Bundle
Fifty Quick Ideas
3 BooksGet all three books for the price of two! Fifty Quick Ideas books are full of practical, real-world techniques that you can use to improve teamwork, build better products and build them in a better way.
Growing Agile: Coach's Guide Series
4 BooksThis bundle provides a collection of training and workshop plans for a variety of agile topics. The series is aimed at agile coaches, trainers and ScrumMasters who often find themselves needing to help teams understand agile concepts. Each book in the series provides the plans, slides, handouts and activity instructions to run a number of...
Marionette.js A to Z
Complete Scala Bundle
3 BooksScala is a general-purpose programming language and it's getting extremely popular these days. Some say that learning Scala could be a challenging task. My experience, however, suggests that this is actually a myth that has very little to do with reality. With the right approach, learning Scala can be easy, fun and rewarding.The first book from...
Build A Better Backbone App
3 BooksThe best way to learn new development skills is through experience, but that takes time you don't have.Get the best of both worlds with this bundle: you'll learn how to produce modern web applications by learning from experienced developers like Derick Bailey and David Sulc. BackboneJS is one of the favorite tools on the web today, but it...