Acknowledgments |
|
xix | |
Introduction |
|
xxi | |
Why PowerShell? |
|
xxii | |
Who This Book Is For |
|
xxii | |
About This Book |
|
xxii | |
Part I: Fundamentals |
|
1 | (112) |
|
|
3 | (10) |
|
Opening the PowerShell Console |
|
|
4 | (1) |
|
|
4 | (2) |
|
Exploring PowerShell Commands |
|
|
6 | (2) |
|
|
8 | (2) |
|
|
8 | (1) |
|
Learning About General Topics |
|
|
9 | (1) |
|
|
10 | (1) |
|
|
11 | (2) |
|
2 Basic Powershell Concepts |
|
|
13 | (24) |
|
|
13 | (6) |
|
Displaying and Changing a Variable |
|
|
14 | (1) |
|
|
14 | (2) |
|
|
16 | (3) |
|
|
19 | (4) |
|
|
20 | (1) |
|
Integers and Floating Points |
|
|
20 | (1) |
|
|
21 | (2) |
|
|
23 | (3) |
|
|
24 | (1) |
|
Using the Get-Member cmdlet |
|
|
25 | (1) |
|
|
25 | (1) |
|
|
26 | (7) |
|
|
26 | (3) |
|
|
29 | (2) |
|
|
31 | (2) |
|
|
33 | (2) |
|
|
35 | (2) |
|
|
37 | (10) |
|
Starting a Windows Service |
|
|
37 | (1) |
|
|
38 | (4) |
|
Piping Objects Between Commands |
|
|
38 | (1) |
|
Piping Arrays Between Commands |
|
|
39 | (1) |
|
Looking at Parameter Binding |
|
|
40 | (2) |
|
|
42 | (4) |
|
Setting the Execution Policy |
|
|
42 | (2) |
|
|
44 | (2) |
|
|
46 | (1) |
|
|
47 | (14) |
|
Understanding Control Flow |
|
|
48 | (1) |
|
Using Conditional Statements |
|
|
49 | (5) |
|
Building Expressions by Using Operators |
|
|
49 | (1) |
|
|
50 | (1) |
|
|
51 | (1) |
|
|
51 | (1) |
|
|
52 | (2) |
|
|
54 | (5) |
|
|
54 | (3) |
|
|
57 | (1) |
|
|
58 | (1) |
|
The do/while and do/until Loops |
|
|
58 | (1) |
|
|
59 | (2) |
|
|
61 | (8) |
|
Working with Exceptions and Errors |
|
|
62 | (1) |
|
Handling Nonterminating Errors |
|
|
63 | (1) |
|
Handling Terminating Errors |
|
|
64 | (2) |
|
Exploring the $Error Automatic Variable |
|
|
66 | (1) |
|
|
67 | (2) |
|
|
69 | (10) |
|
|
70 | (1) |
|
|
70 | (1) |
|
Adding Parameters to Functions |
|
|
71 | (5) |
|
Creating a Simple Parameter |
|
|
72 | (1) |
|
The Mandatory Parameter Attribute |
|
|
73 | (1) |
|
|
74 | (1) |
|
Adding Parameter Validation Attributes |
|
|
74 | (2) |
|
|
76 | (2) |
|
|
76 | (1) |
|
Making the Function Pipeline Compatible |
|
|
77 | (1) |
|
|
77 | (1) |
|
|
78 | (1) |
|
|
79 | (12) |
|
Exploring Default Modules |
|
|
80 | (4) |
|
Finding Modules in Your Session |
|
|
80 | (1) |
|
Finding Modules on Your Computer |
|
|
81 | (1) |
|
|
82 | (2) |
|
The Components of a PowerShell Module |
|
|
84 | (2) |
|
|
84 | (1) |
|
|
84 | (2) |
|
Working with Custom Modules |
|
|
86 | (2) |
|
|
86 | (1) |
|
|
87 | (1) |
|
|
88 | (1) |
|
|
88 | (1) |
|
|
89 | (2) |
|
8 Running Scripts Remotely |
|
|
91 | (16) |
|
Working with Scriptblocks |
|
|
92 | (4) |
|
Using Invoke-Command to Execute Code on Remote Systems |
|
|
93 | (1) |
|
Running Local Scripts on Remote Computers |
|
|
94 | (1) |
|
Using Local Variables Remotely |
|
|
95 | (1) |
|
|
96 | (5) |
|
|
97 | (1) |
|
Invoking Commands in a Session |
|
|
98 | (1) |
|
Opening Interactive Sessions |
|
|
98 | (1) |
|
Disconnecting from and Reconnecting to Sessions |
|
|
99 | (2) |
|
Removing Sessions with Remove-PSSession |
|
|
101 | (1) |
|
Understanding PowerShell Remoting Authentication |
|
|
101 | (4) |
|
|
102 | (1) |
|
Double Hopping with CredSSP |
|
|
103 | (2) |
|
|
105 | (2) |
|
|
107 | (6) |
|
|
108 | (1) |
|
|
108 | (3) |
|
|
108 | (1) |
|
|
109 | (1) |
|
|
109 | (1) |
|
|
110 | (1) |
|
|
110 | (1) |
|
|
111 | (1) |
|
|
112 | (1) |
Part II: Automating Day-To-Day Tasks |
|
113 | (100) |
|
10 Parsing Structured Data |
|
|
117 | (20) |
|
|
118 | (8) |
|
|
118 | (4) |
|
|
122 | (1) |
|
Project 1: Building a Computer Inventory Report |
|
|
123 | (3) |
|
|
126 | (5) |
|
Creating Excel Spreadsheets |
|
|
126 | (1) |
|
Reading Excel Spreadsheets |
|
|
127 | (1) |
|
Adding to Excel Spreadsheets |
|
|
128 | (1) |
|
Project 2: Creating a Windows Service Monitoring Tool |
|
|
129 | (2) |
|
|
131 | (5) |
|
|
131 | (1) |
|
|
132 | (2) |
|
Project 3: Querying and Parsing a REST API |
|
|
134 | (2) |
|
|
136 | (1) |
|
11 Automating Active Directory |
|
|
137 | (20) |
|
|
138 | (1) |
|
Installing the ActiveDirectory PowerShell Module |
|
|
138 | (1) |
|
Querying and Filtering AD Objects |
|
|
139 | (4) |
|
|
139 | (2) |
|
|
141 | (1) |
|
Project 4: Finding User Accounts That Haven't Changed Their Password in 30 Days |
|
|
141 | (2) |
|
Creating and Changing AD Objects |
|
|
143 | (6) |
|
|
143 | (2) |
|
|
145 | (1) |
|
Project 5: Creating an Employee Provisioning Script |
|
|
146 | (3) |
|
Syncing from Other Data Sources |
|
|
149 | (7) |
|
Project 6: Creating a Syncing Script |
|
|
150 | (1) |
|
Mapping Data Source Attributes |
|
|
150 | (1) |
|
Creating Functions to Return Similar Properties |
|
|
151 | (2) |
|
Finding Matches in Active Directory |
|
|
153 | (2) |
|
Changing Active Directory Attributes |
|
|
155 | (1) |
|
|
156 | (1) |
|
|
157 | (16) |
|
|
157 | (1) |
|
|
158 | (3) |
|
Creating a Service Principal |
|
|
158 | (2) |
|
Non interactively Authenticating with Connect-AzAccount |
|
|
160 | (1) |
|
Creating an Azure Virtual Machine and All Dependencies |
|
|
161 | (6) |
|
Creating a Resource Group |
|
|
161 | (1) |
|
Creating the Network Stack |
|
|
162 | (2) |
|
Creating a Storage Account |
|
|
164 | (1) |
|
Creating the Operating System Image |
|
|
164 | (2) |
|
|
166 | (1) |
|
Automating the VM Creation |
|
|
167 | (1) |
|
Deploying an Azure Web App |
|
|
167 | (1) |
|
Creating an App Service Plan and Web App |
|
|
167 | (1) |
|
Deploying an Azure SQL Database |
|
|
168 | (4) |
|
Creating an Azure SQL Server |
|
|
168 | (1) |
|
Creating the Azure SQL Database |
|
|
169 | (1) |
|
Creating the SQL Server Firewall Rule |
|
|
170 | (1) |
|
Testing Your SQL Database |
|
|
171 | (1) |
|
|
172 | (1) |
|
|
173 | (20) |
|
|
174 | (1) |
|
|
174 | (4) |
|
Authenticating with the Root User |
|
|
174 | (1) |
|
Creating an IAM User and Role |
|
|
175 | (2) |
|
Authenticating Your IAM User |
|
|
177 | (1) |
|
Creating an AWS EC2 Instance |
|
|
178 | (6) |
|
The Virtual Private Cloud |
|
|
178 | (1) |
|
|
179 | (1) |
|
|
180 | (1) |
|
|
180 | (1) |
|
Assigning an AMI to Your EC2 Instance |
|
|
181 | (1) |
|
|
182 | (2) |
|
Deploying an Elastic Beanstalk Application |
|
|
184 | (4) |
|
|
184 | (2) |
|
|
186 | (2) |
|
Creating a SQL Server Database in AWS |
|
|
188 | (3) |
|
|
191 | (2) |
|
14 Creating A Server Inventory Script |
|
|
193 | (20) |
|
|
194 | (1) |
|
Creating the Project Script(s) |
|
|
194 | (1) |
|
Defining the Final Output |
|
|
194 | (1) |
|
Discovery and Script Input |
|
|
194 | (2) |
|
|
196 | (1) |
|
Thinking Ahead: Combining Different Types of Information |
|
|
196 | (3) |
|
|
199 | (2) |
|
Querying Windows Management Instrumentation |
|
|
201 | (7) |
|
|
202 | (1) |
|
Operating System Information |
|
|
202 | (1) |
|
|
203 | (2) |
|
|
205 | (3) |
|
|
208 | (2) |
|
Script Cleanup and Optimization |
|
|
210 | (2) |
|
|
212 | (1) |
Part III: Building Your Own Module |
|
213 | |
|
15 Provisioning A Virtual Environment |
|
|
217 | (14) |
|
PowerLab Module Prerequisites |
|
|
218 | (1) |
|
|
219 | (2) |
|
|
219 | (1) |
|
Creating a Module Manifest |
|
|
219 | (1) |
|
Using Built-In Prefixes for Function Names |
|
|
220 | (1) |
|
|
220 | (1) |
|
Automating Virtual Environment Provisioning |
|
|
221 | (7) |
|
|
221 | (2) |
|
Creating Virtual Machines |
|
|
223 | (2) |
|
|
225 | (3) |
|
Testing the New Functions with Pester |
|
|
228 | (1) |
|
|
229 | (2) |
|
16 Installing An Operating System |
|
|
231 | (10) |
|
|
231 | (1) |
|
|
232 | (3) |
|
|
232 | (2) |
|
|
234 | (1) |
|
Automating OS Deployments |
|
|
235 | (2) |
|
Storing Encrypted Credentials on Disk |
|
|
237 | (1) |
|
|
238 | (1) |
|
|
239 | (1) |
|
|
240 | (1) |
|
17 Deploying Active Directory |
|
|
241 | (12) |
|
|
242 | (1) |
|
Creating an Active Directory Forest |
|
|
242 | (1) |
|
|
242 | (8) |
|
Saving Secure Strings to Disk |
|
|
243 | (1) |
|
Automating Forest Creation |
|
|
244 | (2) |
|
|
246 | (4) |
|
Building and Running Pester Tests |
|
|
250 | (2) |
|
|
252 | (1) |
|
18 Creating And Configuring A SQL Server |
|
|
253 | (12) |
|
|
253 | (1) |
|
Creating the Virtual Machine |
|
|
254 | (1) |
|
Installing the Operating System |
|
|
254 | (1) |
|
Adding a Windows Unattended Answer File |
|
|
255 | (1) |
|
Adding the SQL Server to a Domain |
|
|
256 | (3) |
|
Installing the SQL Server |
|
|
257 | (1) |
|
Copying Files to the SQL Server |
|
|
257 | (2) |
|
Running the SQL Server Installer |
|
|
259 | (1) |
|
Automating the SQL Server |
|
|
259 | (4) |
|
|
263 | (1) |
|
|
263 | (2) |
|
|
265 | (10) |
|
A Second Look at New-PowerLabSqlServer |
|
|
266 | (3) |
|
|
269 | (3) |
|
|
272 | (3) |
|
20 Creating And Configuring An IIS Web Server |
|
|
275 | |
|
|
275 | (1) |
|
|
276 | (1) |
|
Building Web Servers from Scratch |
|
|
277 | (1) |
|
The WebAdministration Module |
|
|
277 | (4) |
|
Websites and Application Pools |
|
|
278 | (3) |
|
Configuring SSL on a Website |
|
|
281 | (3) |
|
|
284 | |
Index |
|
28 | |