* (asterisk), 131–134, 185–186
(backslash), 135
` (backtick), 143–144
[] (brackets), 52, 69, 154, 185
& (call operator), 91
, (comma), 151
/ (division) operator, 131
$ (dollar sign), 134, 137, 193
:: (double colon), 52, 138, 140
% (modulus) operator, 131
? (question mark), 133–135, 185–186
= operator, 131
%= operator, 132
*= operator, 132
+= operator, 131
-= operator, 131
/= operator, 132
() (parentheses), 137
| (pipe operator), 62
.. (range operator), 154
< redirection operator, 143
> redirection operator, 143
>> redirection operator, 143
; (semicolon), 152
_ (underscore) character, 39
$_ variable, 41
1 to (interactive) remoting, 460–461
1 to many (fan-out) remoting, 461–465
2> redirection operator, 143
2&1 redirection operator, 143
2>> redirection operator, 143
accelerators (type), 71–72
Access Control Entry (ACE), 236–237
accounts, disabling, 366
ACE (Access Control Entry), 236–237
ADSI (Active Directory Services Interfaces), 353–355
ChangeLocalAdminPassword.ps1 script. See ChangeLocalAdminPassword.ps1 script
managing with PowerShell
administrator tips and guidelines, 359–360
CTP2 improvements, 361
DirectoryEntry class, 357
DirectorySearcher class, 357–358
DirectoryServices.ActiveDirectory namespace, 358–359
managing with Window Script Host (WSH), 355–356
objects
ADSI methods, 363–364
base object methods, 365
binding, 361–363
creating, 365
deleting, 366
example, 372–373
modifying, 366
moving, 366
searching for, 367–372
overview, 353
ActiveX Data Objects (ADO), 355
AD. See Active Directory
Add method, 364
Add-ACE cmdlet, 236–237
Add-ConnectorToTier cmdlet, 454
Add-Content cmdlet, 207
Add-Module cmdlet, 475
Add-Numbers function, 159
Add-RemotelyManagedComputer cmdlet, 454
Add-RemotelyManagedDevice cmdlet, 454
Add-UserToUserRole cmdlet, 454
add/remove cmdlets (Operations Manager PowerShell interface), 454
addition (+) operator, 131
AddPerm function, 230
ADO (ActiveX Data Objects), 355
ADODB (ADSI OLE DB) provider, 355
ADSI (Active Directory Services Interfaces), 353–355, 363–364
ADSI OLE DB (ADODB) provider, 355
[ADSI] type accelerator, 357
[ADSISearcher] type accelerator, 358
agent cmdlets (Operations Manager PowerShell interface), 432–436
agents, 434–436
alias cmdlets, 43–44
Alias property, 332
aliases, 10
alias cmdlets, 43–44
avoiding in scripts, 303
listing supported aliases, 43
overview, 42
persistent aliases, 44
All Users host-specific profile, 87–88
All Users profile, 87
AllMatches parameter (Select-String cmdlet), 176
AllSigned execution policy, 101, 294
analyzing objects with Get-Member cmdlet, 56–59
-and operator, 136
appending content to files, 207, 210–211
Approve-AgentPendingAction cmdlet, 455
arguments, 29
arithmetic expressions, 130
arithmetic operators, 131
array literals. See arrays
array operators, 137
array subexpressions operator (@), 137, 151
accessing elements of, 154
array slicing, 155
array subexpressions operator (@), 137, 151
defining, 151–153
definition of, 151
multidimensional arrays, 151, 156–157
negative index, 154
one-dimensional arrays, 151
operators, 151
range operator (..), 154
assemblies, 54–56
assignment expressions, 130
assignment operators, 131–132
asterisk (*), 131–134, 185–186
attributes. See specific attributes
authentication, 363
AuthenticationLevel property, 280–282
auto-completion feature, 30–32
automating file system management with ProvisionWebFolders.ps1 script. See ProvisionWebFolders.ps1 script
available cmdlets, listing with Get-Command cmdlet, 36–39
awk scripting language, 60
background jobs. See PSJobs
backslash (), 135
backtick (`), 143–144
-band operator, 136
base object methods, 365
Bash shell, 8–15
BeginProcesses method, 323
BIG_DIR_COUNTER counter, 14
binding objects, 361–363
bitwise operators, 135–136
-bnot operator, 136
-bor operator, 136
Bourne Again Shell. See Bash shell
Bourne shell, 15
Break keyword, 148
-bxor operator, 136
built-in variables, 40–42
C shell, 15
CA signed certificates, 109–111
cache, GAC (Global Assembly Cache), 56, 316
call operator (&), 91
CAs (certificate authorities), 107
CategoryInfo property (ErrorRecord object), 146
CEC (Common Engineering Criteria), 268
certificate authorities (CAs), 107
Certificate Creation Tool (Makecert.exe), 101
Certificate.Format.ps1xml file, 75
certificate stores, 112
Certificate Trust List (CTL), 117
CA signed certificates, 109–111
certificate stores, 112
obtaining, 107–108
PVK Digital Certificate Files Importer, 112
self-signed certificates, 108–109
ChangeLocalAdminPassword.ps1 script, 373
DataTable objects, 380
DirectorySearcher class, 383–384
Get-ADObject function, 381
Get-CurrentDomain function, 381
Get-ScriptHeader function, 380
header, 377
LibraryCrypto.ps1 library file, 376
New-PromptYesNo function, 377–378
New-RandomPassword function, 377–379
$OnlineServers variable, 384–385
Out-File cmdlet, 380
$Password variable, 384–385
Read-Host cmdlet, 382–383
running, 374
sequence of actions, 374–376
Set-ChoiceMessage function, 377–378
ChangePassword method, 364
classes. See specific classes
Clear-Inherit cmdlet, 224, 233–234
Clear-SD cmdlet, 235
CLI (command line interface)
aliases, 43–44
cmdlets. See specific cmdlets
command syntax, 28–30
navigating, 30
overview, 28
Tab key auto-completion, 30–32
variables, 39–42
CLI shells, 8
cmd command prompt, accessing PowerShell from, 27
Cmdlet class, 322
cmdlet keyword, 470
cmdlets. See specific cmdlets
code signing, 294
CAs (certificate authorities), 107
certificates. See certificates
definition of, 106
enterprise code distribution, 117
overview, 105–106
process, 106–107
public code distribution, 117
signed code distribution, 115–117
signing scripts, 112–113
verifying digital signatures, 113–114
column index values (multidimensional arrays), 156
combining strings, 194
comma (, ), 151
comma-separated value (CSV) files. See CSV files
command line interface. See CLI
command shell (Operations Manager PowerShell interface), 426
commands. See specific commands
comments, 300
CommitChanges method, 365
committing transactions, 245–247
Common Engineering Criteria (CEC), 268
common parameters for cmdlets, 33–34
Community Technology Preview (CTP), 457
comparison expressions, 130
comparison operators, 132–133, 190–191
Complete-PSTransaction cmdlet, 244
configuration files, digitally signing, 294
configuration information, putting at beginning of scripts, 299
Configure-WSMan.ps1 script, 459
Confirm parameter, 34, 305–306
Connect-Mailbox cmdlet, 396
Console, 30
constructors, 52
Contains method, 180
-contains operator, 133
Continue keyword, 148
conversion errors (types), 70
ConvertFrom-StringData cmdlet, 473–475
converting strings to lowercase/uppercase, 183–184
ConvertTo-Csv cmdlet, 215
ConvertTo-Html cmdlet, 64
Copy-Item cmdlet, 221
core cmdlets, 197–198
counters, 14
Create method, 364
CreateObject method, 356
CreateRunspace method, 486
CSV (comma-separated value) files, 214–216
CTL (Certificate Trust List), 117
CTP (Community Technology Preview), 457
Current User’s host-specific profile, 88
Current User’s profile, 88
current working directory
listing contents of, 8–10
retrieving, 198
setting, 198
custom cmdlets, 320–323
custom output formats, 75–79
custom parameters, 327–329
custom snap-ins, 323–327
cut command, 60
d regular expression characters, 135
DATA sections, 473–475
Database parameter (New-Mailbox cmdlet), 396
databases, 392–393
DataTable objects, 380
DCL (Digital Command Language), 15
Debug parameter (cmdlets), 33
debugging in PowerShell 2.0, 475–477
$DebugPreference variable, 42
default security, 100
defining types, 68–71
Delete method, 364
delimiters, 60
descriptive names, 303
designing scripts. See scripts
Detailed Description section (PowerShell help), 36, 337
developing scripts. See scripts
development life cycle model, 296–297
dialog boxes. See specific dialog boxes
Digital Command Language (DCL), 15
digital signatures. See code signing
dir command, 29
DIR_COUNTER counter, 14
DIR_MIN_SIZE variable, 14
DIR_PERCENT_BIG_MAX variable, 14
directories
current working directory
listing contents of, 8–10
retrieving, 198
setting, 198
pushing onto list of locations, 199
recalling from list of locations, 199–200
directory.sh script, 12–14
DirectorySearcher class, 56–59, 357–358, 367, 383–384
Filter property, 367–368
PageSize property, 371
PropertiesToLoad property, 372
search example, 372–373
SearchRoot property, 367
SearchScope property, 371
SizeLimit property, 371
DirectoryServices.ActiveDirectory namespace, 358–359
Disable-Mailbox cmdlet, 396
Disable-NotificationSubscription cmdlet, 455
Disable-PsBreakpoint cmdlet, 476
Disable-Rule cmdlet, 455
disabling user accounts, 366
Dismount-Database cmdlet, 392
distribution, 115–117
division (/) operator, 131
DLLS (dynamic link libraries), 91
do/while loop, 164–165
dollar sign ($), 134, 137, 193
DOSShell, 16
dot sourcing, 91
DotNetTypes.Format.ps1xml file, 75
double colon (::), 138–140
drives
accessing, 82–85
adding, 200
definition of, 81
mounting, 85–86
viewing, 81–82
DumpPerm function, 229–230
dynamic link libraries (DLLs), 91
EMC (Exchange Management Console), 388
EMS (Exchange Management Shell)
accessing, 388–389
databases management/reporting, 392–393
definition of, 388
help, 389–390
recipient management/reporting, 394–397
server management/reporting, 390–391
storage group management/reporting, 391–392
Enable-Mailbox cmdlet, 394–395
Enable-NotificationSubscription cmdlet, 455
Enable-PsBreakpoint cmdlet, 476
Enable-Rule cmdlet, 455
enable/disable cmdlets (Operations Manager PowerShell interface), 455
EndProcessing method, 323
EndsWith method, 180
enterprise code distribution, 117
equal operator, 190
error handling
error trapping, 148–150
$Error variable, 145
ErrorRecord object, 145–146
nonterminating errors, 145
terminating errors, 145
with throw keyword, 150
in transactions, 248–249
type conversion errors, 70
with ubiquitous parameters, 146–147
ErrorAction parameter, 34, 146–147
$ErrorActionPreference variable, 42
ErrorDetails property (ErrorRecord object), 146
ErrorRecord object, 145–146
errortraps1.ps1, 149
errortraps2.ps1, 149
ErrorVariable parameter, 34, 146–147
escape sequences, 143–144
Add-Member cmdlet, 67
arrays, 69
hash tables, 69
integers, 68
overview, 65–67
strings, 68
type accelerators, 71–72
type conversion errors, 70
type definitions, 68–71
type references, 69
types.ps1xml file, 68
Event ID 1221 messages, reporting on, 406–416
events, 52
example-cmdlet function, 160–163
Examples section (PowerShell help), 36
Exception property (ErrorRecord object), 146
Exchange Management Console (EMC), 388
Exchange Management Shell. See EMS
Exchange Server
EMC (Exchange Management Console), 388
EMS (Exchange Management Shell) accessing, 388–389
database management/reporting, 392–393
definition of, 388
help, 389–390
recipient management/reporting, 394–397
server management/reporting, 390–391
storage group management/reporting, 391–392
GetDatabaseSizeReport.ps1 script, 397–406
GetEvent1221Info.ps1 script, 406–416
overview, 387
ProvisionExchangeUsers.ps1 script, 416–423
ExecQuery method, 270
AllSigned, 101
best practices, 294
definition of, 100
RemoteSigned, 101–103
Restricted, 100
setting, 103–105
explicit scope indicators, 89
explorer.exe, replacing
overview, 480–481
PSShell Secure Kiosk GPO, creating, 481
Windows Shell Replacement settings, configuring, 481–482
Export-Alias cmdlet, 44
Export-CliXml cmdlet, 213–214
Export-Csv cmdlet, 216
Export-DataTable function, 401, 406, 410, 416
Export-Mailbox cmdlet, 396
Export-ManagementPack cmdlet, 455
Extended Type System. See ETS
extensions, PowerShell Community Extensions (PSCX) package, 64–65
-f (format) operator, 195–196
fan-in remoting, 461
fan-out remoting, 461–465
fields, 52
file systems
automating with ProvisionWebFolders.ps1 script. See ProvisionWebFolders.ps1 script
core cmdlets, 197–198
drives
adding, 200
removing, 201
files. See files
folders. See folders
navigating
Get-Location cmdlet, 198
overview, 198
Pop-Location cmdlet, 199–200
Push-Location cmdlet, 199
Set-Location cmdlet, 198
objects
owners, setting, 234–235
permissions, 236–237
security descriptors, clearing, 235
files. See also specific files
appending content to, 207
creating, 205
CSV files, 214–216
library files. See library files
MOF (Managed Object Format) files, 278
moving, 206
reading, 206
removing, 205
renaming, 206
searching contents of, 207–208
SPC (Software Publishing Certificate) file, 112
testing for, 208
writing, 206–207
XML files. See XML files
FileSystem.Format.ps1xml file, 75
Filter property (DirectorySearcher class), 367–369
filters, 163–164
creating, 201
moving, 202–203
owners, 229
permissions, 229–234
removing, 202
renaming, 203–204
testing for, 204–205
for loop, 165
foreach loop, 166
format operator, 141–142, 195–196
format operator (-f), 291
format strings, 141–142
Format-Custom cmdlet, 74
Format-Table cmdlet, 61, 74, 291, 406
Format-Wide cmdlet, 74
FormatNumber function, 270
formatting output, 73–79, 195–196
FullControl, granting to user’s Web folder, 224
FullyQualifiedErrorId property (ErrorRecord object), 146
function-parameters argument (functions), 157
function providers, 162
functions. See also specific functions
compared to filters, 163–164
defining, 157–163
definition of, 157
function providers, 162
multiline functions, 158
GAC (Global Assembly Cache), 56
gathering script requirements effectively, 297
-ge operator, 132
geocoding in MMC 3.0 (sample interface)
Get-Coordinates cmdlet, 344–347
Get-Coordinates MMC, 349–352
Get-Coordinates User Control, 347–349
Get-ACL cmdlet, 232
Get-ADObject cmdlet, 64
Get-ADObject function, 381, 418, 421
get-agent cmdlet, 432–434, 452
Get-AgentPendingAction cmdlet, 452
Get-Alert cmdlet, 452
Get-AlertDestination cmdlet, 452
Get-AlertHistory cmdlet, 452
Get-Alias cmdlet, 43–44
Get-AuthenticodeSignature cmdlet, 113–114
Get-ChildItem cmdlet, 112, 188
Get-ClientAccessServer cmdlet, 391
Get-Command cmdlet, 33, 36–39, 327
Get-Connector cmdlet, 452
Get-Content cmdlet, 84–85, 206–207
Get-Coordinates cmdlet, 344–347
Get-Coordinates MMC, 349–352
Get-Coordinates User Control, 347–349
Get-CurrentDomain function, 381, 418, 421
get-DefaultSetting cmdlet, 443–447, 452
Get-Diagnostic cmdlet, 452
Get-Discovery cmdlet, 453
Get-Event cmdlet, 453
Get-ExBlog cmdlet, 390
Get-ExCommand cmdlet, 390
Get-ExecutionPolicy cmdlet, 45, 104
Get-FailoverManagementServer cmdlet, 453
Get-GatewayManagementServer cmdlet, 453
supporting with XML files
Detailed Description section, 337
header, 335
Input Type section, 338
Name and Synopsis sections, 335–336
Notes section, 338–339
Output section, 340–341
Parameters section, 337–338
Related Links section, 339
Return Type section, 338
Syntax section, 336–337
Get-Help command, 30
Get-ItemProperty cmdlet, 241, 263
Get-Location cmdlet, 198
Get-Mailbox cmdlet, 396–397
Get-MailboxDatabase cmdlet, 399
Get-MailboxServer cmdlet, 391, 399, 404, 414
Get-MaintenanceWindow cmdlet, 453
get-MaintenanceWindow cmdlet, 449–451
Get-ManagementGroupConnection cmdlet, 453
Get-ManagementPack cmdlet, 453
get-ManagementServer cmdlet, 441–442, 453
Get-Member cmdlet, 52, 56–59, 277
Get method, 364
Get-Monitor cmdlet, 453
Get-MonitorHierarchy cmdlet, 453
Get-MonitoringClass cmdlet, 453
Get-MonitoringClassProperty cmdlet, 453
Get-MonitoringObject cmdlet, 453
Get-MonitoringObjectGroup cmdlet, 453
Get-MonitoringObjectPath cmdlet, 453
Get-MonitoringObjectProperty cmdlet, 453
Get-MyMessage cmdlet, 471
Get-NotificationAction cmdlet, 453
Get-NotificationEndpoint cmdlet, 453
Get-NotificationRecipient cmdlet, 453
Get-NotificationSubscription cmdlet, 453
Get-OperationsManagerCommand cmdlet, 431, 453
Get-Override cmdlet, 453
Get-PerformanceCounter cmdlet, 453
Get-PerformanceCounterValue cmdlet, 453
Get-PrimaryManagementServer cmdlet, 453
Get-Process cmdlet, 62
Get-Process command, 29
Get-PsBreakpoint cmdlet, 476
Get-PsCallStack cmdlet, 476
Get-PSCommand cmdlet, 390
Get-PsJob cmdlet, 467
Get-Psprovider cmdlet, 81
Get-PSSnapin cmdlet, 92, 95, 326
Get-Recovery cmdlet, 453
Get-RegValue cmdlet, 251–253
Get-RelationshipClass cmdlet, 453
Get-RelationshipObject cmdlet, 453
Get-RemoteEventLog cmdlet, 409
Get-RemoteEventLog function, 410, 415
Get-RemotelyManagedComputer cmdlet, 453
Get-RemotelyManagedDevice cmdlet, 453
Get-ResultantCategoryOverride cmdlet, 453
Get-ResultantRuleOverride cmdlet, 453
Get-ResultantUnitMonitorOverride cmdlet, 453
Get-RootManagementServer cmdlet, 453
Get-Rule cmdlet, 453
Get-RunAsAccount cmdlet, 454
Get-Runspace cmdlet, 264
Get-ScriptHeader function, 380, 413, 420
Get-Service cmdlet, 50
Get-State cmdlet, 454
Get-StorageGroup cmdlet, 391
get-TaskResult cmdlet, 439–440, 454
Get-Tier cmdlet, 454
Get-Tip cmdlet, 390
Get-TransportServer cmdlet, 391
Get-UserRole cmdlet, 454
Get-WmiObject cmdlet, 271–273, 276, 399
get/set cmdlets (Operations Manager PowerShell interface), 452–454
GetDatabaseSizeReport.ps1 script, 397–406
GetEvent1221Info.ps1 script, 406–416
GetEx method, 364
GetHelloWorldPSSnapIn, 323, 326
GetInfo method, 364
GetInfoEx method, 364
GetObject method, 355
Global Assembly Cache (GAC), 56, 316
global scope, 88–89
configuring WinRM and WinRS with, 122–125
creating, 104–105
PSShell Secure Kiosk GPO, creating, 481
Graphical PowerShell (PowerShell 2.0), 18, 468–469
Group Policy Administrative Template, 104
Group Policy Objects. See GPOs
grouping operators, 137
-gt operator, 132
GUI shells, 8
hard-coding configuration information, avoiding, 300
hashes
hash tables, 69
one-way hashes, 106
help
available cmdlets, listing with Get-Command cmdlet, 36–39
in EMS (Exchange Management Shell), 389–390
help topics, displaying with Get-Help cmdlet, 34–35
in Operations Manager PowerShell interface, 431
PowerShell help sections, 36
Windows PowerShell home page, 21
Help.Format.ps1xml file, 75
HelpMessage property, 331
history of shells, 15–16
hives (Registry), 239, 242–243
HKCU: hive, 239
HKLM: hive, 239
hosting applications, 87
hosts, 87
hyphen (-), 154
IADs interface, 354
IADsContainer interface, 354
if/else loop, 167
IIsWebService class, 276–277
ImpersonationLevel property, 280–282
Import-Alias cmdlet, 44
Import-CliXml cmdlet, 213–214
Import-Csv cmdlet, 215, 221, 418
Import-LocalizedData cmdlet, 473
Import-Mailbox cmdlet, 396
Input Type section (PowerShell help), 36, 338
Get-Help cmdlet. See Get-Help cmdlet
required parameters, 302–303
ValidateCount attribute, 334–335
ValidateLength attribute, 332
ValidatePattern attribute, 333
ValidateRange attribute, 333
ValidateSet attribute, 334
Insert method, 181
install-agent cmdlet, 434–435, 455
Install-AgentByName cmdlet, 455
Install-ManagementPack cmdlet, 455
install/uninstall cmdlets (Operations Manager PowerShell interface), 455
instance members, 52–53
instructions, including with scripts, 301–302
integers, 68
interactive remoting, 460–461
interfaces, 354
internationalization (scripts), 472–473
InvocationInfo property (ErrorRecord object), 146
Invoke method, 365
Invoke-Command cmdlet, 264, 462–464
Invoke-Expression cmdlet, 18
Invoke-WMIMethod cmdlet, 283–284
InvokeGet method, 365
jobs
background jobs (PowerShell 2.0), 466–467
PSJobs, 18
join operator, 194
Join-Path cmdlet, 221
joining strings, 194
keys (Registry)
creating, 253–254
removing, 256–257
keywords. See specific keywords
kiosks, 8
Korn shell, 15
labels, 167
-le operator, 132
Length property (System.String class), 185
length of strings, determining, 185
creating, 97
LibraryCrypto.ps1 library file, 376
registering, 93–95
removing, 96–97
snapins, adding to console, 94–95
snapins, removing from console, 96
LibraryCrypto.ps1 library file, 376
LibraryRegistry.ps1 script
Get-RegValue function, 251–253
overview, 249–251
Remove-RegKey function, 256–257
sample application, 257–262
Set-RegKey function, 253–254
Set-RegValue function, 254–255
LoadWithPartialName method, 55, 485
local scope, 89
locating tasks, 437–438
logical operators, 135–136, 368
definition of, 164
do/while loop, 164–165
for loop, 165
foreach loop, 166
if/else loop, 167
while loop, 164
lowercase, converting strings to, 183
ls command, 8–9
-lt operator, 132
mailboxes
creating, 394–396
GetDatabaseSizeReport.ps1 script, 397–406
GetEvent1221Info.ps1 script, 406–416
managing, 396–397
ProvisionExchangeUsers.ps1 script, 416–423
reporting on, 396–397
maintenance mode cmdlets (Operations Manager PowerShell interface)
get-MaintenanceWindow cmdlet, 449–451
maintenance window reason codes, 448
new-MaintenanceWindow cmdlet, 448–449
set-MaintenanceWindow cmdlet, 451–452
maintenance windows, 448–452
Makecert.exe, 101
Managed Object Format (MOF) file, 278
management interface
custom cmdlets, 320–323
custom snap-ins, creating, 323–327
Get-Help cmdlet. See Get-Help cmdlet
input validation, 332–335
overview, 315
parameters, 327–332
PowerShell SDK, 316–319
runspaces, 341–344
scenario: geocoding in MMC 3.0
Get-Coordinates cmdlet, 344–347
Get-Coordinates MMC, 349–352
Get-Coordinates User Control, 347–349
management server cmdlets (Operations Manager PowerShell interface)
default setting paths, 445–447
get-DefaultSetting, 443–444
get-ManagementServer, 441–442
set-DefaultSetting, 444–445
set-ManagementServer, 442–443
returning, 441–442
returning settings for, 443–444
setting default settings for, 444–445
specifying, 442–443
Mandatory property, 331
many to 1 (fan-in) remoting, 461
Match operator, 190
-match operator, 134
$MaximumAliasCount variable, 42
$MaximumDriveCount variable, 42
$MaximumErrorCount variable, 42
$MaximumFunctionCount variable, 42
$MaximumHistoryCount variable, 42
$MaximumVariableCount variable, 42
method operators, 138–140
methods. See specific methods
Microsoft Technet, 390
Microsoft Visual Studio Express Edition, downloading, 316
MMC, geocoding in MMC 3.0 (sample interface)
Get-Coordinates cmdlet, 344–347
Get-Coordinates MMC, 349–352
Get-Coordinates User Control, 347–349
modules (PowerShell 2.0), 475
modulus (%) operator, 131
MOF (Managed Object Format) files, 278
moniker strings, 269
MonitorMSVS.ps1 script, 285–291
Mount-Database cmdlet, 392
mounting drives, 85–86
Move-DatabasePath cmdlet, 392
Move-Item cmdlet, 202–203, 206
Move-Mailbox cmdlet, 396–397
Move-StorageGroupPath cmdlet, 391–392
MoveHere method, 364
MoveTo method, 365
multidimensional arrays, 151, 156–157
multiline functions, 158
multiplication (*) operator, 131
multiplying strings, 178
{n} regular expression characters, 135
{n, } regular expression characters, 135
{n, m} regular expression characters, 135
Name parameter (New-Mailbox cmdlet), 396
Name section (PowerShell help), 36, 335
namespaces
definition of, 316
DirectoryServices.ActiveDirectory, 358–359
Root, 275
WMI providers, 275
naming conventions
CLI (command line interface), 39
cmdlets, 32
custom cmdlets, 320
scripting standards, 309–310
negative index, 154
.NET Framework
assemblies, 54–56
benefits of, 51–52
constructors, 52
events, 52
fields, 52
Global Assembly Cache (GAC), 56
instance members, 52–53
methods. See specific methods
objects
analyzing with Get-Member cmdlet, 56–59
benefits of, 49–51
creating with New-Object cmdlet, 53–54
DirectorySearcher, 56–59
overview, 51
properties, 52
references, 69
reflection, 56–59
static members, 52
networking equipment, 8
New-Alias cmdlet, 44
New-CustomMonitoringObject cmdlet, 455
New-DeviceDiscoveryConfiguration cmdlet, 455
New-Item cmdlet, 201, 205, 247
New-LdapQueryDiscoveryCriteria cmdlet, 455
New-Mailbox cmdlet, 395, 418, 422
New-MailboxDatabase cmdlet, 392, 396
New-MailUser cmdlet, 394
New-MaintenanceWindow cmdlet, 448–449, 455
New-ManagementGroupConnection cmdlet, 456
New-MonitoringPropertyValuePair cmdlet, 456
New-Object cmdlet, 53–54
New-PromptYesNo function, 377–378
New-PsBreakpoint cmdlet, 476
New-PSDrive cmdlet, 85–86, 200, 242–243
New-RandomPassword function, 377–379
New-Runspace cmdlet, 464–465
New-StorageGroup cmdlet, 391
New-Tier cmdlet, 456
New-WindowsDiscoveryConfiguration cmdlet, 456
Non-Terminating Errors section (PowerShell help), 36
nonterminating errors, 145
not equal operator, 190
-not operator, 136
-notcontains operator, 133
Notes section (PowerShell help), 36, 338–339
NotMatch parameter (Select-String cmdlet), 176
noTypeInformation parameter (Export-Csv cmdlet), 216
object tree (Operations Manager PowerShell interface), 427–431
objects. See also specific objects
ADO (ActiveX Data Objects), 355
ADSI methods, 363–364
analyzing with Get-Member cmdlet, 56–59
base object methods, 365
benefits of, 49–51
binding, 361–363
deleting, 366
extending with Add-Member cmdlet, 67
extracting from, 183–184
modifying, 366
moving, 366
in Operations Manager PowerShell interface, 427–431
searching for. See searching
one-dimensional arrays, 151
one-liners, 63–65
one-way hashes, 106
$OnlineServers variable, 384–385
Operations Manager PowerShell interface
cmdlets, 432
add/remove cmdlets, 454
default setting paths, 445–447
enable/disable cmdlets, 455
get-agent, 432–434
get-DefaultSetting, 443–444
get-MaintenanceWindow, 449–451
get-ManagementServer, 441–442
get-Task, 437–438
get-TaskResult, 439–440
get/set cmdlets, 452–454
install-agent, 434–435
install/uninstall cmdlets, 455
maintenance window reason codes, 448
new-MaintenanceWindow, 448–449
set-DefaultSetting, 444–445
set-MaintenanceWindow, 451–452
set-ManagementServer, 442–443
start-Task, 438–439
uninstall-agent, 435–436
command shell, 426
help, 431
object tree, 427–431
overview, 425
scripts, 432
operators, 129–130. See also specific operators
-or operator, 136
Out-Default cmdlet, 62–64
Out-File cmdlet, 380, 399, 404, 413
Out-GridView cmdlet, 471
OutBuffer parameter (cmdlets), 34
Output section (Help), 340–341
output, formatting, 73–79, 195–196
OutVariable parameter (cmdlets), 34
P regular expression characters, 135
packages, PowerShell Community Extensions (PSCX) package, 64–65
PageSize property (DirectorySearcher class), 371
parameters. See specific parameters
Parameters section (PowerShell help), 36, 337–338
parentheses, 137
parsing text, 59
Password parameter (New-Mailbox cmdlet), 396
$Password variable, 384–385
pattern matching operators, 133
percent sign (%), 131
folder permissions, 229–234
managing with PowerShell cmdlets
Add-ACE, 236–237
Clear-Inherit, 233–234
Clear-SD, 235
overview, 231–233
Remove-ACE, 237
Set-Owner, 234–235
managing in WSH (Windows Script Host) with SubInACL, 227–231
overview, 227
persistent aliases, 44
Ping class, 53
pipe operator (|), 62
pipeline
accepting input from, 158
one-liners, 63–65
overview, 59–63
PKI (public key infrastructure), 107–108
policies
execution policies, 100–105, 118, 294
GPOs (Group Policy Objects), 104–105, 122–125
Pop-Location cmdlet, 199–200
Position property, 330
PowerShell 2.0
background jobs, 466–467
DATA sections, 473–475
Graphical PowerShell, 468–469
modules, 475
Out-GridView cmdlet, 471
overview, 457
remoting. See remoting
script cmdlets, 469–471
script debugging, 475–477
script internationalization, 472–473
PowerShell Community Extensions (PSCX) package, 64–65
PowerShell development, 16–17
PowerShell SDK. See SDK
PowerShell WMI Explorer, 278
PowerShellCore.format.ps1xml file, 75
PowerShellExecutionPolicy.adm, 104
PowerShellTrace.format.ps1xml file, 75
principle of least privileges, 294–295
PRINT_DIR_MIN variable, 12
private scope, 90–91
privileges, principle of least privileges, 294–295
processing XML files, 213
ProcessRecord method, 323
$Processes variable, 88–91
$ProcessReturnPreference variable, 42
$ProgressPreference variable, 42
production environments, dangers of, 297–298
professionalism in script development, 298–299
profiles, 87–88
projects, setting up, 321–322
properties. See also specific properties
adding to PSObject, 75–76
PropertiesToLoad property (DirectorySearcher class), 372
property operators, 138
core cmdlets, 79–81
drives
accessing, 82–85
definition of, 81
mounting, 85–86
removing, 86
viewing, 81–82
viewing, 81
WMI providers, 275
ProvisionExchangeUsers.ps1 script, 416–423
ProvisionWebFolders.ps1 script, 216
Clear-Inherit cmdlet, 224
Copy-Item cmdlet, 221
FullControl, granting, 224
functions, 218–220
header, 217–218
Import-Csv cmdlet, 221
Join-Path cmdlet, 221
Set-Owner cmdlet, 222
Test-Path cmdlet, 220–221
ps command, 60
PSAdapted view, 66
PSBase view, 66
PSCX (PowerShell Community Extensions) package, 64–65
pseudocode, 297
.ps1 extension, 45
.ps1xml formatting files, 74–75
PSExtended view, 66
$PSHOME variable, 74
PSJobs, 18
PSShell Kiosk
PSShell.exe, 482–484
PSShell.ps1 script, 479, 484–488
shell replacement, 480–482
PSShell.exe, 482–484
PSShell.ps1 script, 479, 484–488
PSSnapIn class, 323
PSTypeNames view, 66
public code distribution, 117
public key infrastructure (PKI), 107–108
Push-Location cmdlet, 199
Push-Runspace cmdlet, 461
pushing directories onto list of locations, 199
Put method, 364
PutEx method, 364
PVK Digital Certificate Files Importer, 112
quantifiers, 192
question mark (?), 133–135, 185–186
QuickRef cmdlet, 390
range operator (..), 154
Read-Host cmdlet, 382–383, 418, 422
Read-only LDAP, 358
reading
CSV files, 215
files, 206–207
Registry values, 241
recalling directories from list of locations, 199–200
Receive-PsJob cmdlet, 467
recipients
managing in EMS (Exchange Management Shell), 394–397
reporting on, 394–397
redirection operators, 142–143
references, 69
reflection, 56–59
[RegEx] type accelerator, 193–194
registering library files, 93–95
Registry
2.0 CTP features, 262–265
core cmdlets, 240
keys, 253–257
LibraryRegistry.ps1 script
Get-RegValue function, 251–253
overview, 249–251
Remove-RegKey function, 256–257
sample application, 257–262
Set-RegKey function, 253–254
Set-RegValue function, 254–255
overview, 239
cmdlets, 244–245
committing, 245–247
how they work, 245
overview, 243–244
starting, 245–247
transactions with errors, 248–249
undoing, 247–248
Registry.format.ps1xml file, 75
regular expressions, 134–135, 191–192
Reject-AgentPendingAction cmdlet, 456
Related Links section (PowerShell help), 36, 339
releases of PowerShell, 22–23
reliability, 310–311
remote management. See WinRM (Windows Remote Management)
RemoteSigned execution policy, 101–103, 294
RemoteSigned policy, 45
centrally managing, 295
fan-in remoting, 461
fan-out remoting, 461–465
interactive remoting, 460–461
overview, 458–460
Universal Code Execution Model, 460
Windows Vista and Windows Server 2008 machines, 465–466
Windows XP SP2 or greater and Windows Server 2003 machines, 465
Remove-ACE cmdlet, 237
Remove-ConnectorFromTier cmdlet, 454
Remove-DisabledMonitoringObject cmdlet, 454
Remove-ItemProperty cmdlet, 242
Remove-Mailbox cmdlet, 396
Remove-MailboxDatabase cmdlet, 392
Remove-ManagementGroupConnection cmdlet, 454
Remove-PsBreakpoint cmdlet, 476
Remove-PSDrive cmdlet, 86, 201
Remove-PSSnapin cmdlet, 96
Remove-RegKey cmdlet, 256–257
Remove-RemotelyManagedComputer cmdlet, 454
Remove-RemotelyManagedDevice cmdlet, 454
Remove-Runspace cmdlet, 265
Remove-StorageGroup cmdlet, 391
Remove-Tier cmdlet, 454
Remove-WMIObject cmdlet, 284–285
RemovePerm function, 231
Rename-Item cmdlet, 203–206
Rename method, 365
Replace method, 182
replace operators, 134, 192–193
replacing
strings, 182
Windows Explorer shell (explorer.exe), 480–482
reporting
on databases, 392–393
on recipients, 394–397
on servers, 390–391
on storage groups, 391–392
repository (WMI), 275–278
Resolve-Alert cmdlet, 456
Restore-Mailbox cmdlet, 396
Restricted execution policy, 100
results of tasks, checking, 439–440
retrieving Registry values, 251–253
Return keyword, 148
Return Type section (PowerShell help), 36, 338
reusability of scripts, 303
rights, principle of least privileges, 294–295
Root namespace, 275
row index values (multidimensional arrays), 156
Run dialog box, accessing PowerShell from, 26
RunspaceInvoke object, 486
definition of, 486
removing, 264–265
running commands with, 263–264
S regular expression characters, 135
SCOM (System Center Operations Manager), 425
script cmdlets (PowerShell 2.0), 469–471
script scope, 89–90
scriptblocks, 170–172
ScriptCmdlets, 18
Scriptomatic, 275
scripts. See also specific scripts
benefits, 15
building with scriptblocks, 170–172
controlling script flow with loops. See loops
creating, 45–47
debugging in PowerShell 2.0, 475–477
decision making in, 167–169
definition of, 45
design
comments, 300
configuration information at beginning of scripts, 299
descriptive names, 303
hard-coding configuration information, avoiding, 300
instructions, 301–302
reusability, 303
status information for script users, 304
validity checks on required parameters, 302–303
variables, 301
WhatIf and Confirm parameters, 305–306
development
dangers of production environment, 297–298
development life cycle model, 296–297
gathering script requirements effectively, 297
professionalism, 298–299
pseudocode, 297
testing, 298
treating scripting projects as actual projects, 295
digitally signing, 294
dot sourcing, 91
internationalization, 472–473
in Operations Manager PowerShell interface, 432
overview, 11
.ps1 extension, 45
RemoteSigned policy, 45
running, 294–295
script cmdlets (PowerShell 2.0), 469–471
scripting standards, 306–307, 309–311
signing, 112–113
WSH (Windows Script Host), 227–231
SDDL (Security Descriptor Definition Language), 235
SDK, 316–319
file contents, 207–208
for objects (DirectorySearcher class)
example, 372–373
examples, 370
Filter property, 367–369
overview, 367
PageSize property, 371
PropertiesToLoad property, 372
SearchRoot property, 367
SearchScope property, 371
SizeLimit property, 371
SearchRoot property (DirectorySearcher class), 367
SearchScope property (DirectorySearcher class), 371
security
best practices, 118–119
code signing. See code signing
default security, 100
execution policies. See execution policies
overview, 99–100
Security Descriptor Definition Language (SDDL), 235
security descriptors, clearing, 235
Select-String cmdlet, 175–177, 207–208
self-signed certificates, 108–109
semicolon (;), 152
servers
management servers. See management servers
managing in EMS (Exchange Management Shell), 390–391
reporting on, 390–391
$Servers variable, 289
Set-ACL cmdlet, 232
Set-AlertDestination cmdlet, 454
Set-Alias cmdlet, 44
Set-AuthenticodeSignature cmdlet, 112–113
Set-ChildItem cmdlet, 82
Set-ChoiceMessage function, 377–378
Set-ClientAccessServer cmdlet, 391
set-DefaultSetting cmdlet, 444–447, 454
Set-ExecutionPolicy cmdlet, 45, 103
Set-ItemProperty cmdlet, 83, 241
Set-Mailbox cmdlet, 396
Set-MailboxDatabase cmdlet, 392, 396
Set-MailboxServer cmdlet, 391
Set-MaintenanceWindow cmdlet, 451–452, 454
set-ManagementServer cmdlet, 442–443, 454
Set-Owner cmdlet, 222, 234–235
Set-ProxyAgent cmdlet, 454
Set-RegKey cmdlet, 253–254
Set-RegValue cmdlet, 254–255
Set-StorageGroup cmdlet, 391
Set-TransportServer cmdlet, 391
Set-WMIInstance cmdlet, 282–283
SetInfo method, 364
SetOwner function, 229
SetPassword method, 364
shell replacement (PSShell Kiosk), 480–482
shell scripts. See scripts
shells
Bash shell, 13–14
basic shell use, 8–10
benefits and drawbacks, 8
CLI shells, 8
definition of, 7
graphical versus nongraphical, 8
GUI shells, 8
history of, 15–16
overview, 7
Shfusion.dll, 56
shortcuts (type), 71–72
ShouldProcess method, 34
$ShouldProcessPreference variable, 42
signing code. See code signing
silent installation, 25–26
SizeLimit property (DirectorySearcher class), 371
slash (/), 131
slicing arrays, 155
snapins
adding to console, 94–95
custom snap-ins, creating, 323–327
removing from console, 96
Software Development Kit. See SDK
Software Publishing Certificate (SPC) file, 112
SPC (Software Publishing Certificate) file, 112
Split method, 182
Split operator, 195
square brackets ([]), 52, 69, 154, 185
Start-Discovery cmdlet, 456
Start menu, accessing PowerShell from, 26
Start-PsJob cmdlet, 466
Start-PSTransaction cmdlet, 244
start-Task cmdlet, 438–439, 456
starting
PowerShell, 26–27
tasks, 438–439
transactions, 245–247
StartsWith method, 182
statements. See specific statements
static member accessor (::), 52, 138–140
static members, 52
status information, providing for for script users, 304
Step-Into cmdlet, 476
Step-Out cmdlet, 476
Step-Over cmdlet, 477
Stop-PSJob cmdlet, 467
storage groups
managing in EMS (Exchange Management Shell), 391–392
reporting on, 391–392
[String] type accelerator, 174–175
strings, 68
adding, 177
binding strings, 362
combining, 194
comparison operators, 190–191
converting to lowercase, 183
converting to uppercase, 184
creating, 173–174
definition of, 173
determining length of, 185
extracting from current object, 183–184
extracting strings from, 183
Format operator, 195–196
format strings, 141–142
formatting, 195–196
inserting strings into, 181
join operator, 194
moniker strings, 269
multiplying, 178
overview, 173
querying for substrings, 180
[RegEx] type accelerator, 193–194
regular expressions, 191–192
removing strings from, 181–182
replace operators, 192–193
replacing strings in, 182
Select-String cmdlet, 175–177
Split operator, 195
[String] type accelerator, 174–175
System.String class, 174, 178–180
Contains method, 180
EndsWith method, 180
Insert method, 181
Length property, 185
Remove method, 181–182
Replace method, 182
Split method, 182
StartsWith method, 182
SubString method, 183
ToLower method, 183
ToString method, 183–184
ToUpper method, 184
Trim method, 184
trimming, 184
wildcards, 185–189
subexpressions grouping operator ($), 137
SubInACL utility
AddPerm function, 230
DumpPerm function, 229–230
RemovePerm function, 231
SetOwner function, 229
syntax, 227–228
SubString method, 183
subtraction (-) operator, 131
switch statement, 168–169
Synopsis section (PowerShell help), 36, 335
Syntax section (PowerShell help), 36, 336–337
System Center Operations Manager (SCOM), 425
System.String class, 174, 178–180
Contains method, 18
EndsWith method, 180
Insert method, 181
Length property, 185
Remove method, 181–182
Replace method, 182
Split method, 182
StartsWith method, 182
SubString method, 183
ToLower method, 183
ToString method, 183–184
ToUpper method, 184
Trim method, 184
Tab key completion, 138
TargetObject property (ErrorRecord object), 146
tasks
checking results of, 439–440
locating, 437–438
starting, 438–439
task cmdlets (Operations Manager PowerShell interface)
get-Task, 437–438
get-TaskResult, 439–440
start-Task, 438–439
templates, Group Policy Administrative Template, 104
terminating errors, 145
Terminating Errors section (PowerShell help), 36
Test-Item cmdlet
in ProvisionWebFolders.ps1 script, 220–221
testing for files, 208
testing for folders, 204–205
testing
for files, 208
for folders, 204–205
scripts, 298
text, parsing, 59
throw keyword, 150
throwing errors, 150
ToLower method, 183
ToString method, 183–184
ToUpper method, 184
transactions (Registry)
cmdlets, 244–245
committing, 245–247
how they work, 245
overview, 243–244
starting, 245–247
transactions with errors, 248–249
undoing, 247–248
trapping errors
errortraps1.ps1 example, 149
errortraps2.ps1 example, 149
syntax, 148
trap scopes, 150
Trim method, 184
trimming strings, 184
[ADSI], 357
[ADSISearcher], 358
[WMIClass] type accelerator, 273–274
[WMISearcher] type accelerator, 274
[WMI] type accelerator, 273
types
arrays, 69
conversion errors, 70
defining, 68–71
definition of, 53
ETS (Extended Type System)
Add-Member cmdlet, 67
overview, 65–67
types.ps1xml file, 68
hash tables, 69
integers, 68
references, 69
string. See strings
type accelerators, 71–72
[ADSISearcher], 358
[ADSI], 357
[RegEx] type accelerator, 193–194
[WMIClass] type accelerator, 273–274
[WMISearcher] type accelerator, 274
[WMI] type accelerator, 273
type operators, 136
types.ps1xml file, 68
ubiquitous parameters, 146–147
unary operators, 136
underscore (_) character, 39
Undo-PSTransaction cmdlet, 244, 248
undoing transactions, 247–248
uninstall-agent cmdlet, 435–436, 455
Uninstall-ManagementPack cmdlet, 455
uninstalling
agents, 435–436
Windows PowerShell 1.0, 23–24
Universal Code Execution Model, 460
Unrestricted execution policy, 103, 118, 294
uppercase, converting strings to, 184
Use-PSTransaction cmdlet, 245
user accounts, disabling, 366
UserPrincipalName parameter (New-Mailbox cmdlet), 396
users, providing status information for, 304
useTransaction parameter (New-Item cmdlet), 247
ValidateCount attribute, 334–335
ValidateLength attribute, 332
ValidatePattern attribute, 333
ValidateRange attribute, 333
ValidateSet attribute, 334
validating input. See input validation
variables. See also specific variables
best practices, 301
built-in variables, 40–42
definition of, 39
naming, 39
VerbNounPSSnapIn naming convention, 323
Verbose parameter (cmdlets), 33
$VerbosePreference variable, 42
verifying digital signatures, 113–114
versions of PowerShell, 22–23
views, 66
Virtual Memory System (VMS), 15
$VirtualMachines variable, 290
Visual Studio Express Edition, downloading, 316
VMS (Virtual Memory System), 15
W regular expression characters, 135
/w parameter (dir command), 29
Wait-PSJob cmdlet, 467
wbemtest.exe, 275
websites, Windows PowerShell home page, 21
Where-Object cmdlet, 63
while loop, 164
whitespace delimiters, 60
Window Script Host (WSH), managing Active Directory with, 355–356
Windows Explorer shell (explorer.exe), replacing
overview, 480–481
PSShell Secure Kiosk GPO, creating, 481
Windows Shell Replacement settings, configuring, 481–482
Windows Management Instrumentation Query Language (WQL), 278–279
Windows Management Instrumentation. See WMI
Windows permissions. See permissions
Windows PowerShell home page, 21
Windows PowerShell Programmer’s Guide, 97
Windows Remote Management. See WinRM
Windows Remote Shell (WinRS), 121–125, 295
Windows Script Host. See WSH
Windows Server remoting settings, 465
Windows Server 2008
enabling PowerShell 1.0 on, 22–23
remoting settings, 465–466
Windows Shell Replacement settings, configuring, 481–482
Windows Vista remoting settings, 465–466
Windows XP SP2 remoting settings, 465
WinRM (Windows Remote Management)
configuring, 119–120
GPO settings, 122–125
installing, 24
overview, 119
WinRS (Windows Remote Shell), 120–122
WinRS (Windows Remote Shell), 121–125, 295
WMI (Windows Management Instrumentation)
advantages of, 267–268
challenges, 268
definition of, 267
MonitorMSVS.ps1 script, 285–291
objects, connecting to, 269
in PowerShell
AuthenticationLevel property, 280–282
Get-WmiObject cmdlet, 271–273
ImpersonationLevel property, 280–282
Invoke-WMIMethod cmdlet, 283–284
Remove-WMIObject cmdlet, 284–285
Set-WMIInstance cmdlet, 282–283
[WMIClass] type accelerator, 273–274
[WMISearcher] type accelerator, 274
[WMI] type accelerator, 273
PowerShell WMI Explorer, 278
providers and namespaces, 275, 278
repository, exploring, 275–278
Windows Management Instrumentation Query Language (WQL), 278–279
in WSH, 269–270
WMI Query Language (WQL), 270
[WMI] type accelerator, 273
[WMIClass] type accelerator, 273–274
[WMISearcher] type accelerator, 274
WQL (Windows Management Instrumentation Query Language), 278–279
WQL (WMI Query Language), 270
writing CSV files, 216
WSH (Windows Script Host), 16
managing Active Directory with, 355–356
permissions, managing with SubInACL, 227–231
WMI (Windows Management Instrumentation) in, 269–270
WSMAN (Windows Remote Management), 295, 459
WSMan settings, configuring, 27–28
appending, 210–211
creating, 209–210
deleting from, 212
Export-CliXml cmdlet, 213–214
Import-CliXml cmdlet, 213–214
loading, 212–213
modifying, 211–212
overview, 208
processing, 213
supporting custom cmdlets with
Detailed Description section, 337
header, 335
Input Type section, 338
Name and Synopsis sections, 335–336
Notes section, 338–339
Output section, 340–341
Parameters section, 337–338
Related Links section, 339
Return Type section, 338
Syntax section, 336–337
-xor operator, 136
[x-y] operator, 133
[xy] operator, 133