sample scripts
online Web site, 30
SAPIEN Press
Web site, 30
SAPIEN PrimalScript, 32
-scope parameter, 89
scopes, 17, 25, 26, 66, 67, 68, 69, 70, 71
trapping errors, 232
ScopeTest.ps1, 68, 69
script blocks
modularization, 211, 213
script scopes, 66
Script1.ps1 listing, 233
Script2.ps1 listing, 233
scripting
arrays, 93, 94, 95, 96, 97
associative, 97, 98, 99, 100, 101, 102
best practices, 307
aliases, 307, 308
comments, 310, 311
constructs, 308, 309
loops, 308, 309
parameters, 307
switches, 309, 310
variables, 306
escape characters, 117, 118, 119
objects, 102
creating new, 115, 116, 117
methods, 102, 103, 104, 105
properties, 102
PowerShell, 5, 6
variables, 81, 82, 83
as objects, 105, 107, 108, 109, 110, 111, 112, 113, 114, 115
Clear-Variable, 91, 92
environmental, 88
Get-Variable, 84, 85, 87
New-Variable, 90
Remove-Variable, 92, 93
Set-Variable, 88, 89, 90
scripts, 4
debugging, 236, 237, 238
mode to trace script execution, 239, 240, 241, 242, 243, 244
editors, 31, 32
error handling, 229, 230
error trapping tiips, 234, 236
ErrorAction argument, 230, 231
scopes, 232
throwing exceptions, 232, 233, 234
trap handlers, 231, 232
Internet download
dangers, 47, 48
reasons not running
execution policies, 43, 44
self-signed certificates, 44, 45
trusted scripts, 42, 43
restarting list of computers, 32, 33, 34, 35, 37, 38
running basics, 17, 18
SAPEN Press Web site, 30
scopes, 66, 67, 68, 69, 70, 71
security, 39, 40
digital signatures, 41
reasons won't run, 40, 41
SDK (Software Development Kit) download, 44
SearchForAllUsers.ps1 listing, 292
SearchForAllUsersAdvanced.ps1 listing, 293
SecureString objects, 48, 49, 50
security
administrator dangers, 46, 47
alternate credentials, 45, 46
Internet script download, 47, 48
passwords, 48, 49, 50
scripts, 39, 40
digital signatures, 41
reasons won't run, 40, 41
scripts not running
execution policies, 43, 44
self-signed certificates, 44, 45
trusted scripts, 42, 43
WMI (Windows Management Instrumentation), 75
SELECT queries, 321
Select-Object cmdlet, 448
Select-String cmdlet, 449, 450
self-signed certificates, 44, 45
Service2HTML.ps1 listing, 203
ServiceDemo.ps1 listing, 185
ServicePack.ps1 listing, 345
ServicePack.vbs listing, 345
ServicePack2.ps1 listing, 346
ServicePack3.ps1 listing, 346
services
Windows management
listing, 264
managing, 266
start, 264, 265
stopping, 265, 266
ServicesGrid.ps1 listing, 208
Set-Acl cmdlet, 451
Set-Alias cmdlet, 452
Set-AuthenticodeSignature cmdlet, 453, 454
Set-Content cmdlet, 455
Set-Date cmdlet, 456
Set-ExecutionPolicy cmdlet, 457
Set-Item cmdlet, 458
Set-ItemProperty cmdlet, 459, 460
Set-Location cmdlet, 7, 461
SetPermswithCACLS.ps1 listing, 272, 273
Set-PSDebug cmdlet, 239, 462
Set-Service cmdlet, 266, 464
Set-TraceSource cmdlet, 465, 466
Set-Variable, 88, 89, 90
Set-Variable cmdlet, 467
shell scripting languages, 3
shells
creating new, 28
shortcuts
predefined aliases, 299, 302
ShowDialog() method, 57
simple arrays, 93
single quotation marks
string values, 322
snapins
cmdlets, 225, 226
snap-ins
basic shell listing, 12
cmdlets, 12, 13
listing cmdlets, 12
Snover, Jeffrey
blog address, 192
Software Development Kit (SDK)
download, 44
sorting data outputs
Sort-Object cmdlet, 194, 195, 196, 197
Sort-Object cmdlet, 194, 195, 196, 197, 468
special characters, 24
regular expressions, 146
special operators
call, 135, 136
format, 136, 138
range, 134
-replace, 131, 132, 133
type, 133, 134
Split-Path cmdlet, 469, 470
stacks
locating to top, 8
locations, 8
start services
Windows management, 264, 265
Start-Service cmdlet, 264, 265, 471, 472
Start-Sleep cmdlet, 473
Start-Transcript cmdlet, 474
stop services
Windows management, 265, 266
Stop-Process cmdlet, 48, 475, 476
Stop-Service cmdlet, 265, 266, 477, 478
Stop-Transcript cmdlet, 479
string objects, 21, 55
string types, 502, 503, 504, 505
string variables
embedded, 22, 23
strings
conversion from objects, 134
SecureString objects, 48, 49, 50
substitutions
cmdlets, 18, 19
SubString() method, 21
Suspend-Service cmdlet, 480, 481
Switch statements
logic constructs, 175, 176, 177, 178
SwitchContinue.ps1 listing, 179
switches
scripting best practices, 309, 310
SwitchNoContinue.ps1 listing, 179
SwitchRegex.ps1 listing, 177
syntax
expressions, 173
For statements, 169
system forms, 205, 206, 207, 208, 209
System.Windows.Forms assembly, 57