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.
Jeff Woolsey
Windows Server/Hybrid Cloud
@wsv_guy
Bundles that include this book
Table of Contents
Foreword by: Jeff Woolsey iii
Acknowledgements iv
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
Contents xiii
Introduction 20
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
Authentication 50
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
Twitter 250
Other books by these authors
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
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) and EPUB (for phones, tablets and 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.
Learn more about Leanpub's ebook formats and where to read them