Master PowerShell Tricks Volume 2
Master PowerShell Tricks Volume 2
About the Book
There are many cool things about Windows PowerShell. For me three of the most awesome things are the following:
1. If you don’t like the way Windows PowerShell does things, you can change it.
2. If Windows PowerShell can’t do something you need, you can add it.
3. The Windows PowerShell community is super dedicated, and will help you do both one and two.
Now, to be honest at times, it is necessary to write hundreds and hundreds of lines of arcane code, to dive into the deepest and darkest mysteries of programing, and even to learn about things like API’s, Constructors, Events, threading, ACL’s, DACL’s, CACL’s and maybe even Tetradactylies. Then again, most of the time it is not. In fact, it has been years and years since I wrote a hundreds and hundreds of lines of arcane code.
It is almost as if the Windows PowerShell team deliberately tried to make Windows PowerShell easy to use and easy to learn. Hmm … I wonder if that approach would ever catch on? Anyway, there used to be an old saw: “Ease of use is directly opposed to program capability.” Or, in other words, if it is easy to use, it probably is not all that powerful. Well, PowerShell changes that … dramatically.
And yet, Windows PowerShell is also deceptively easy to use. One can go from Get-Service and Get-Process or even Get-Date to some pretty complicated stuff in like one line of code.
This is why item number three is so important. The authors of this book: Dave, Sean, Will, Mick, Thomas and Allan are all Windows PowerShell experts, and have even been recognized by Microsoft as community leaders. So, this means not only do they know their stuff, but they are also great at sharing that knowledge with the community. Sean Kearney is even an Honorary Scripting Guy – a very elite group indeed!
One of the great way that MVP’s share their knowledge and experience is via MVP Days a traveling road show that was started by Dave and Cristal Kawula. This is a very well run event, and I have had the opportunity to speak at two of the events … it is cool, and it is fun.
So grab this book, get it autographed, and learn how to master some awesome PowerShell tricks. It is cool.
Microsoft Scripting Guy
Foreword Ed Wilson “The Scripting Guy” iii
From Dave v
About the Authors vi
Dave Kawula - MVP vi
Sean Kearney - MVP vii
Thomas Rayner - MVP vii
Allan Rafuse – MVP viii
Will Anderson – MVP ix
Mick Pletcher – MVP x
Ed Wilson – The Scripting Guy xi
Technical Editors xii
Cristal Kawula – MVP xii
Emile Cabot - MVP xii
Kai Poynting xiii
North American MVPDays Community Roadshow 1
Structure of the Book 2
Sample Files 3
Additional Resources 3
Chapter 1 5
PowerShell Regex to Get Value Between Quotation Marks 5
Chapter 2 7
How to Send an Email Whenever a File Gets Changed 7
Chapter 3 8
Using PowerShell to Add Groups to Accept messages only Distribution list members 8
The Code 9
Chapter 4 10
Installing and Finding Modules 10
Why use Install-Modules 10
Module Dependencies 10
Managing Repositories 11
Finding Modules in the Repositories 11
Installing a Module 13
Proxy Configuration 14
Chapter 5 15
Use PowerShell to Validate Parameters for you 15
Common PowerShell Functions – NO Validation 16
PowerShell Features for Parameters 16
Problem 1 16
Problem 2 17
Problem 3 17
Other Parameter Validation Features 18
Chapter 6 19
PowerShell – My Way to Prepare a SQL Server VM 19
Template File 20
A look at library-PrepareSQLServer.ps1 21
Running the script 23
Chapter 7 25
Building Gold VHDx images with PowerShell 25
Define the Variables 26
Build $unnatendSource 26
Chapter 8 32
Using Try Catch to help with Decision Making in a Script 32
Chapter 9 36
Invoking your SCCM Client Remotely with PowerShell 36
Chapter 10 38
Use PoweShell to Parse RSS Feeds 38
Chapter 11 44
How to alter the public IP Address of an Azure Virtual Machine using PowerShell 44
The Challenge 44
Data formatting or using an existing example 44
Make the change 46
Chapter 12 48
Get the Public IP of an Azure VM with PowerShell 48
Chapter 13 49
SCCM Local Administrator Reporting with PowerShell 49
Chapter 14 58
Configuring Power Settings using PowerShell 58
Chapter 15 73
Automated SCCM Endpoint Full System Scan upon Infection with Email Notification 73
Chapter 16 79
Laptop Mandatory Reboot Management with SCCM and PowerShell 79
Chapter 17 84
Set Windows Features with Verification 84
Chapter 18 90
Easily Restore a Deleted Active Directory User with PowerShell 90
Chapter 19 91
Getting Large Exchange Mailbox Folders with PowerShell 91
Chapter 20 95
Getting your Organizations Largest Exchange Mailboxes with PowerShell 95
Chapter 21 99
Just Enough Administration (JEA) First Look 99
So how do you get started? 99
Chapter 22 105
Does a String Start or End in a Certain Character? 105
Chapter 23 107
Using PowerShell to List All the Fonts in a Word Document 107
Chapter 24 109
Find PowerShell Scripts in the GUI 109
Chapter 25 116
How to use PowerShell as an Administrative Console 116
Chapter 26 118
How to Erase Files based on Date using PowerShell 118
Chapter 27 121
Join us at MVPDays and meet great MVP’s like this in person 121
Live Presentations 121
Video Training 121
Live Instructor-led Classes 121
Consulting Services 122
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.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $12 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.