` ,], [, ,cmet and, comments #, (wildcard), ? directory), (parent .. ++ directory), (current . = / −= − += + * * Add-Type Add-PSSnapinSqlServerProviderSnapin100 Add-PSSnapinSqlServerCmdletSnapin100 Add-PSSnapin add-num.ps1 Add-Member Add-History Add-Content Add-Computer AccessLevel (ACLs), lists control access classes, abstract A % $_, $?, !, SYMBOLS Cs(cescnrllists), control (access ACLs drs idwn xesos(AWE), Extensions Windowing Address bc tick) (back = = = sae$ad 4,21 0,213 203, 201, 148, and, $ escape 225 209, and, concatenation eaienme,50 number, negative 50 decrements, 50 number, positive 52 49, 47, concatenation, 100 wildcard, 52 operator, string , 6 50 36, 50 , , , 114 114 , , (increment), 101 50 50 50 244 244 50 50 , 521 101 , , , , 520 parameter, , , 0 1 22 21, 20, 507 512 107, 106, 50 162 4–4,20 6,507 261, 260, 243–244, 512 1 60 21, 97 COPYRIGHTED97 MATERIAL 1,215 214, 520 520 5,42 404 402, 356, , , seik(*) asterisk arrays, pedxA(cmdlets), A Appendix clauses, join ANSI-standard aliases. service, Agent ‘uoCoeadAt_hikOf’policy, Off’’ Auto_Shrink and ‘‘Auto_Close Auto_Close, Statistics, Update Auto Statistics, Create Auto , SQL authentication, W AdesWnoigExtensions), Windowing (Address AWE table, AWBuildVersion and, recovery disaster availability, Auto_Shrink, variables, automatic nlssServices, Analysis NISQL, ANSI -and, logs, event analytic l Programs, All plcto vn log, event Application ALTER_PROCEDURE ALTER_LOGIN ALTER_DATABASE AdventureWorksTest admin aktc ( tick back B AWEAllocated property AutomatedPolicyEvaluationMode AUDIT_LOGIN_FAILED args arguments, diitaieeetlogs, event administrative sae$ad 4,21 0,213 203, 201, 148, and, $ escape 225 209, and, concatenation idad 100 wildcard, 52 operator, string 79 switch, as 78–79 defining, leig 6,430 168, filtering, 0,33 8,36 9,397 391, 386, 384, 383, 203, 6,270 269, 6 50 36, , 8 81 78, 48–49 database, See 220. ` ) 78–80 2,480 325, letaliases client 2,480 325, 11 4,13 7,17 7,19 200, 199, 178, 177, 176, 173, 148, , e also See 233 table, 2,468 328, 9,20 378 200, 199, , 124 , 235 113–115 236 126–127 243 507–530. 325 0,407 402, 325 , , WQL 297–298 234 124 323–324 5,255 254, Index e also See 327–328 5,42 404 402, 356, 480–485 cmdlets ,

Index Backup-DataBase.ps1

Backup-DataBase.ps1, 289, 290 CheckOnSchedule, 270 backups, 308–313, 451 Checkpoint-Computer, 512 best practice, 327 CheckPowershellPreqs.bat (listing 1–1), 3–5 database, 308–310 Check-Services function, 423–424 differential, 288, 308, 312 Check-Services.ps1, 424–425 full, 288, 308 Check-SqlServices function, 425–426 monitoring, 468–472 Check-SqlServices.ps1, 426–427 restore, 313–316 child scopes, 86, 87, 99, 117, 511 full backup, 313 CIM (Common Information Model) repository, 161, transaction log backup and full backup, 313–316 162, 220 SMO.Backup and, 309 CIM Studio, 162 SMO.BackupDeviceitem and, 309 CIMOM (Common Information Model ), SQLConnection class and, 309 161, 162 tempdb and, 327 class library, SMO, 290 transaction log, 288, 308, 311 classes, 159. See also specific classes uspBackupDB, 288–289 abstract, 162 Batch-Test.bat, 17, 18 ClienNetworkProtocol, 203 best practices. See also standards dynamic, 162 data protection, 327 extension, 162, 198 database design, 324–327 hierarchy, 162 Best Practices: Maintenance, 270 .NET, 6, 209, 221, 265, 283, 521, 526 PowerShell coding, 329–331 Policy, 268, 273, 277, 278 Set-StrictMode and, 511 server events, 220 standards and, 317 ServerNetworkProtocolProperty, 211, 212, binary large objects (BLOBs), 214, 326 213, 393, 394 BLOBs (binary large objects), 214, 326 SqlService, 198, 212, 216, 427 ‘‘blocked process threshold’’ option, 229, 440, 441, SqlServiceAdvancedProperty, 216, 217, 218 442, 443, 449 static, 162 BLOCKED_PROCESS_REPORT, 229, 439 StdRegProv, 190, 191, 192, 193 blockings, 229–232, 439–444 Win32_Environment, 186, 187, 189 bottlenecks, 401, 409 Win32_LogicalDisk, 95, 162, 163, 453, 457 Browser service, 199, 200, 216, 479 Win32_NTEventlogFile, 163, 164 Business Intelligence Development Studio, 378 Win32_NTLogEvent, 163, 165, 166, 167, 168, 169 Win32_Process, 163, 179–186 Win32_Service, 163, 170–179 C -cle, 51 calc, 17 Clear-Content, 106, 107, 512 calculate-arith2.ps1, 60–61, 72 Clear-EventLog, 136, 137, 512 calculate-arith3.ps1, 69–70 Clear-History, 508 calculate-arith4.ps1, 73–74 Clear-Item, 512 calculate-arith.ps1, 59–60, 80–81 Clear-ItemProperty, 512 (Windows), 17 Clear-Variable, 112, 120, 521 Caption, 179, 186 ClienNetworkProtocol class, 203 CATCH block, 323 client aliases, 207–211 centralized inventory server, 328, 333, 409 client network protocols, 203–207 -ceq, 35, 51 client tools (SQL Server), 378 c:test.log, 66, 67 -clike, 51 -cge, 51 -clt, 51 -cgt, 51 cluster installation example (SQL Server 2008), CH0DE1, 201, 208, 209, 210, 222, 334, 368, 435, 395–399 479 ClusterTemplate.txt, 395–397 Change, 173, 178 Install-Instance.ps1, 397–398 ChangeDefaultPortNumber.ps1, 212–213 ClusterNodes table, 350–354 ChangeStartMode, 173, 177 schema, 351 ChangeStartupParameters.ps1, 216–217 script for creating, 350–351 Check constraint, 320 Upsert-ClusterNode.ps1, 353–354 CheckOnChanges, 270 uspUpsertClusterNodes.sql, 351–353

532 -cmatch, cmdlets, cmd.exe ClusterTemplate.txt table, Clusters Get-PSBreakpoint Get-Process leigad 34–38 and, filtering 31 documentation, 22–23 and, shell command cea 346 schema, vnig 221 eventing, 136–140 and, logs event Get-PSSession Get-PSProvider Get-PSDrive Get-PSCallStack Get-Member Get-Location Get-Item Get-History Get-Help Get-EventSubscriber Get-Eventlog Get-Event Get-Content Get-Command Get-ChildItem Format-Wide Format-Table Format-List Format-Custom Exit-PSSession Enter-PSSession Encode-SqlName Decode-SqlName Debug-Process Copy-Item Convert-UrnToPath Clear-Variable Clear-History Clear-EventLog Clear-Content Add-PSSnapinSqlServerProvider Add-PSSnapinSqlServerCmdletSnapin100 Add-PSSnapin Add-History Add-Content uspUpsertClusters.sql Upsert-Cluster.ps1 CreateClusters.sql omtigad 39–42 and, formatting oesa-nad 507–511 and, snap-in Core hnelcto ih 96–98 with, location change 244 3,49 3,41 513 431, 430, 429, 139, 4,22 5,262 256, 252, 249, Snapin100 6 81,507–530 18–19, 16, 51 , ,1,2,9,508 96, 22, 16, 2, 4,24 6,20 513 280, 261, 254, 249, , 507 31–38, , 2,22 3,55 1,57 519 517, 516, 515, 435, 222, 221, , 512 103, 102, 99, , 346–350 . 9 39,18 6,26 514 246, 163, 108, 93–94, 19, , . See 115 , 107 106, 89, 63, 62, 508 246, , 245, 25, 19, , 527 523, 39, , 523 42, 41, 40, 39, 27, , 507 , 512 107, 106, , 6 7 4,53 514 513, 249, 97, 96, , 136, 134, 133, 132, 130, 129, , 523 198, 42, 41, 40, 39, , 507 261, 260, 243–244, , See 244 , 9 0,11 2,27 248, 247, 121, 101, 100, 99, , 523 39, , 513 152, , 508 , 512 107, 106, , ,19 9 94–95 19, , 508 , 258 257, 256, 246, , 258 257, 256, 246, , 521 120, 112, , 512 137, 136, , Get-Member 0,510 508, , ,19 Get-Process ,19 4,258 246, , , 348–350 , 347 , 395–397 2,23 2,435 224, 223, 221, , 347–348 , , irsf.sa.aaeet 28 Microsoft.WsMan.Management, 27 Microsoft.PowerShell.Utility, 26 Microsoft.PowerShell.Security, 25–26 Microsoft.PowerShell.Management, 25 Microsoft.PowerShell.host, 27 Microsoft.PowerShell.Diagnostics, 24–25 Microsoft.PowerShell.core, 512–519 and, snap-in Management 112 111, with, variables manage 98–106 with, files/directories manage 507–530 list, euiysa-nad 519–520 and, snap-in Security otn n,38–39 and, sorting rcse n,1117 1–1,5759 522 517–519, 513–514, 151–157, and, processes 44 oriented, object Limit-EventLog Invoke-Sqlcmd Invoke-PolicyEvaluation Invoke-History Get-WmiObject Get-Variable Get-Service Get-PSSnapin Get-PSSessionConfiguration Start-Process Show-EventLog Set-Variable Set-StrictMode Set-Service Set-PSDebug Set-Location Set-Item Set-ExecutionPolicy Set-Content Select-Object Rename-Item Remove-Variable Remove-Item Remove-EventLog Remove-Event Register-WmiEvent Read-Host Push-Location Pop-Location Out-String Out-Printer Out-Null Out-Host Out-GridView Out-File Out-Default New-Variable New-Item Move-Item snap-ins. 143–151 and, services 281 7,17 9,23 0,26 6,528 263, 206, 204, 203, 198, 187, 172, See 2,517 121, , 527 , 527 , 526 136, , 515 118, 117, 116, 102, 101, 99, , 85,527 58–59, , 515 105, 99, , 527 , snap-ins 9 144–146 39, , 5–5,517 511 150–151, 75, 74, , 73, 72, 71, , 517 107, 106, 89, 66, 65, , 516 106, 105, 99, , 516 104, 99, , 527 , 526 39, , 1,118–119 112, , 509 24, 19, , 1,19 529 119, 112, , 517 97, 96, 22, 21, , 516 435, 224, 223, 221, , 515 98, 96, , 527 , 526 117–118, 116, 112, , 4,253–255 246, , 514 164, 163, 162, 95, 53, , 5,57 518 517, 152, , 517 513, 140, 138, 137, 136, , 168, 166, 165, 100, 95, 37, 34, , 516 98, 96, , 3,10 515 140, 136, , 510 115, , 511 , 1,1910 527 119–120, 112, , 516 137, , 2,22 435 222, 221, , 2 6 520 26, 22, , 4,28 280, 278, 246, , ,19 cmdlets 533

Index cmdlets (continued) cmdlets (continued) -computerName parameter, 163, 164, 175, 201, Start-Service, 148–149 208 Start-Transcript, 25, 90, 91 concatenation Stop-Process, 155–157, 522 +, 47, 49, 52, 59 Stop-Service, 146–148 back tick and, 209, 225 Stop-Transcript, 25, 90, 91 ConcatName, 78, 79, 85, 89, 90 syntax, 28–31 conditional statements, 52–54 Unregister-Event, 221, 223, 224, 435 conditions, 260, 263–268 Utility snap-in and, 520–530 Create method, 265 verb-noun format, 18, 28, 329 Drop method, 266 Wait-Process, 152, 519 Configuration Manager, 185, 197, 218, 378. See also Where-Object, 25, 30, 31, 34, 35, 100, 119, 132 WMI Provider for Configuration Management Write-Debug, 73–74, 75 -confirm switch parameter, 30, 137, 147, 148, Write-EventLog, 136, 138, 139, 519 149, 156, 157 Write-Host, 28, 59, 60, 61, 62, 64, 65, 530 Connectivity Components (SQL Server), 378 Write-Output, 64, 65, 473, 530 console, writing to, 64–65 -cne, 35, 51 consumer (WMI), 162 -cnotlike, 51 -contains, 35 -cnotmatch, 51 ConvertFrom-Csv, 521 coding standard (PowerShell), 329–331 ConvertFrom-SecureString, 519 Collect-HostPerfmon.ps1, 414–416 ConvertFrom-StringData, 521 Collect-SQLPerfmonData.ps1, 406–407 Convert-Path, 512 columns ConvertTo-Csv, 521 adding, 307–308 ConvertTo-Html, 522 listing, 305–306 ConvertTo-SecureString, 520 naming conventions, 319 ConvertTo-Xml, 522 removing, 306–307 Convert-UrnToPath, 246, 258 -command, 22, 23 Copy-Item, 99, 102, 103, 512 command chaining, 25, 30–31 Copy-ItemProperty, 512 command console, 12, 13 Core snap-in, 24–25 launching PowerShell with, 11 cmdlets related to, 507–511 command shell, 22–23 CreatDiskUsagebyServer.sql, 455–456 CommandLine, 179, 180, 186 Create method, 265 CreateClusters.sql, 347 command-line interfaces, GUIs v., 1–2 commands CREATE_DATABASE, 236 CreateDatabaseSpace.sql, 461–462 cmdlets. See cmdlets CreateDatabases.ps1, 368–369 native, 16–18 CreateDiskSpace.sql, 452 script, 20–22 CreateHosts.sql, 337–338 shell function. See functions CreateKey method, 193 types, 16 CREATE_LOGIN, 233 comments CreatePolicy.ps1, 273–275 # and, 21, 60 CREATE_PROCEDURE, 237 best practice, 330 CreateServerAlias2008.ps1, 211 multiline, 21 Create-Servers.ps1, 356 stored procedures and, 321–322 CreationDate, 179, 180 Common Information Model Object Manager (CIMOM), CSName, 179 161, 162 current directory (.), 97 Common Information Model (CIM) repository, 161, cursors, 322 162, 220 C:MyPsTranscripts.txt file, 90, 91 Community Technology Preview, 3. See also PowerShell Compact edition, 378 Compare-Object, 521 D comparison operators, 35, 51–52. See also specific Data Definition Language. See DDL comparison operators data protection standards/best practices, 327 Complete-Transaction, 512 data queries, 221 -computername option, 151 ‘‘Database Auto Options Disabled’’ policy, 481–485

534 D scripts, DDL Language), Definition (Data DDL dcomcnfg, security, DCOM schema, dbo owner, object as DBO dbaLib.ps1, types, data date/datetime and, variables values, date DataCollection, DEADLOCK_GRAPH DDL_SERVER_LEVEL_EVENTS DDL_PROCEDURE_EVENTS DDL_LOGIN_EVENTS dba_MonitorBackups dbaLib.ps1 DataSet DatabaseSpace Services, Engine Database Engine, Database databases. Advisor, Tuning Engine Database aaae table, Databases oioig 235–236 monitoring, 328 location, file 461–468 monitoring, growth, file 324–327 practices, standards/best design 487–489 and, scripts DDL 325 practices, best digsa-n srp)ad 260–261 and, (script) snap-ins adding cea 373 schema, tlzto f 467–468 of, utilization 461 schema, 461–462 of, creation uspUpsertDatabases.sql Upsert-Database.ps1 CreateDatabases.ps1 scratch MyDBTest MyDB2 AdventureWorksTest admin M cea,502–503 schemas, XML 503–506 users, 491–494 types, data user-defined 496–498 views, user 494–496 tables, 498–500 procedures, stored 487 and, SMO 489–491 schemas, 500–501 functions, 487–489 databases, efrac n,326 and, performance 236–239 monitoring, objects, 318 conventions, naming Msad 297–304 and, SMOs 325 of, size 7,480 479, 298–299 , 468 328, , 328 , class, 160 e also See 224 299–304 , 487–506. 321 , 465 247 160 8,285 284, 368–373 1,26 2,437 328, 226, 214, table, rc vn class, event trace tables; , 321 e also See 233 461–468 trdprocedure, stored 297–298 , 323 7,46 4,446 441, 436, 378, 47 , 370–373 , 368–369 , pcfi databases specific 236 , 369–370 , scripts 1,26 487 246, 219, 235 378 2,444 226, iksaeuae monitoring, usage, space disk and, availability high recovery, disaster olrsmo ($) symbol dollar views), management (dynamic DMVs triggers, DML statements, DML Framework), Management (Declarative DMF group, Users COM Distributed DisplayName, eal schema, default formatter, default constraint, Default DEFAULT, (-), decrement eu vn logs, event debug Debug, deadlocks, Description -desc DeleteValue DeleteClientAlias.ps1 Delete Decode-SqlName Debug-Process $DebugPreference -Debug DROP_DATABASE Drop do-while server do-until access cannot guest domain DiskUsageByServer DiskSpace Disable-PSBreakpoint DisableListenOnAllIPs.ps1 Disable-ComputerRestore -detailed -description erctdfeatures, deprecated DEMOPC, drives, debugging, elrtv aaeetFaeok(DMF), Framework Management Declarative ietre,mngn,cdesfor, cmdlets managing, directories, backup, differential snap-in, Diagnostics edition, Developer sae aktc n,18 0,23 213 45 203, and, 201, variables 148, and, tick back escape, 114 $_, 114 $?, 455 schema, 455–456 of, creation tlzto f 467–468 of, utilization 452 schema, 452 of, creation aibe 8 3 1,121 111, 93, 88, variable, 94 of, list method, 93 parameter, 30 method, parameter, 0,28 1,20 2,34 379 334, 222, 220, 210, 208, 201, 4,249 247, 2–2,444–449 226–229, 71–75 loop, loop, table, parameter, 171 319 50 266 , method, 321 7,186 171, 56 56–57 8,209 189, 323 , , 9 526 39, 124 7,379 378, 38 320 , 5,513 152, 236 452–454 8,38 312 308, 288, 329 27 4,26 5,258 257, 256, 246, 324 , , 5 115 75, 1 32 31, 194 454–460 DROP_DATABASE , , , 522 117 160 209 451–460 , 513 , 98–106 213–214 0,417 404, 327–328 , 7,475 273, 265 265 535

Index DROP_LOGIN

DROP_LOGIN, 233 Success Audit, 129 DROP_PROCEDURE, 237 Warning, 128 dynamic classes, 162 Get-Eventlog, 129, 130, 132, 133, 134, 136, dynamic management views (DMVs), 404, 417 139, 429, 430, 431, 513 Limit-EventLog, 136, 140, 515 monitoring, 429–433 operational, 124 E Remove-EventLog, 137, 516 editors. See also Notepad Security, 128 Object Editor, 160 Show-EventLog, 136, 137, 138, 140, 513, 517 Object Editor, 166 System, 128 Registry Editor, 193 types of, 124, 125–126 text, 21 WMI and, 164–170 ELSEIF statements, 53 Write-EventLog, 136, 138, 139, 519 Enable-ComputerRestore, 513 event queries, 221 EnableFileStream.ps1, 215 Event Registration Tool, 162 Enable-PSBreakpoint, 522 , 125, 162 Encode-SqlName, 246, 256, 257, 258 eventvwr, 125 -encoding unicode, 63, 66 EventVwr, 125, 137 Enforce (value), 270 exception handling, 330–331 Enterprise edition, 378, 379 exclamation point (!, logical operator), 36, 50 Enter-PSSession, 508, 510 -exclude , 119 Enumkey method, 191, 192 EXIT keyword, 508 EnumProcess(), 292 ExitCode property, 170 environment drives, 93, 94 Exit-PSSession, 508 environment variables, 93, 121–122 Export-Alias, 522 WMI and, 186–189 Export-Clixml, 522 -eq, 35, 51 Export-Console, 508 errors Export-Csv, 522 nonterminating, 67 Export-PSSession, 523 terminating, 67 Express edition, 378 $Error, 67, 68, 114 expressions, 49. See also operators @@ERROR, 323 extended procedures, 233 Error (log entry type), 128 extension classes, 162, 198 error handling, 67–71 ‘‘Error:’’ keyword, 63, 65 error log (SQL Server), 225–226, 433–439 F ErrorAction, 30, 69 -f, 52 $ErrorActionPreference, 115 facet, 260 ErrorControl, 171 failed login attempts, 233–235 ERRORLOG, 225 Failure Audit (log entry type), 129 ErrorVariable, 30, 69 $False, 114 event attributes, 124 file contents, managing, 106–107 Event Collector service, 124 file location, database, 328 event handling, 221–225 file system drives, 93, 95–107 Event Log service, 124–125 list of, 95 event logs, 123–140. See also logs navigating, 96–98 administrative, 124 files analytic, 124 managing, cmdlets for, 98–106 Application, 126–127 writing to, 65–66 Clear-EventLog, 136, 137, 512 FILESTREAM, 214–216 cmdlets related to, 136–140 access level values, 215 debug, 124 enabling, 214, 215 entry types, 128–134 filtering, 34–38 Error, 128 Application log, 168, 430 Failure Audit, 129 Firewall, Windows, 160, 368 Information, 128 ‘‘follow the sun’’ support model, 373

536 omt log, format, keys, foreign functions, scope, function Get-History Get-Process Get-Help Get-Help Get-ExecutionPolicy Get-EventSubscriber Get-Eventlog Get-EventLog Get-Event Get-Date Get-Culture Get-Credential Get-Content Get-ComputerRestorePoint -CommandType *process* Get-Command cmdlet -CommandType Get-Command Get-Command Get-ChildItem getBlockedProcessesDetails Get-AuthenticodeSignature GetAssemblies Get-Alias Get-Acl -ge, G FunctionScope.ps1 ‘‘_function_’’ -full Format-Wide Format-Table Format-List Format-Custom ForEach-Object foreach $ForEach -force for ulTx erhfeature, Search Full-Text Daemon, Filter Full-Text formatting, default, formatter, es n,1,7,8,8,23 224 319 conventions, 223, naming 89, user-defined, 88, 77, 19, and, reuse 80–81 values, returning 20 list-ini, 34 Help, 500–501 and, scripts DDL 78–80 arguments, 5 51 35, loop, 2,40 3,513 431, 430, 429, 5,26 6,513 262, 256, 252, ‘‘cmdlet’’ *service* parameter, parameter, , 55 statement, 92,77–81. 19–20, 6 520 26, , , , 39–42 329 13,57 508–509 507, 31–38, 524 114 , , , 320 523 2,22 3,55 1,57 519 517, 516, 515, 435, 222, 221, 501 , , , , , , 87–88 , , , 1,509 115, 523 513 107, 106, 89, 63, 62, 508 246, 245, 25, 19, 527 523, 39, 523 42, 41, 40, 39, 27, , , , 2,10 3,13 3,16 139, 136, 134, 133, 132, 130, 129, 513 523 198, 42, 41, 40, 39, method, 9 526 39, 143 , 2 33 32, , , 9 0,11 2,27 4,249, 248, 247, 121, 101, 100, 99, 9 523 39, 153 0,252 103, 520 508 57–58 , 9,200 199, 87–88 379 , , e loseicfunctions specific also See , 209 520 435 224, 223, 221, 9 1 2 33 32, 31, 29, , , 513 , 520 238 Get-Process Get-PfxCertificate Get-Member Get-Location Get-Job Get-ItemProperty Get-Item Get-Hotfix Get-Host e-mOjc casWin32_ -class Get-WmiObject Win32_Environment -class Get-WmiObject Win32_Environment -class Get-WmiObject __Namespace -class Get-WmiObject Get-WmiObject Get-WMIEvent.ps1 Get-WMIEvent Get-Variable Get-Unique Get-UICulture Get-Transaction Get-TraceSource Get-Tables.ps1 GetStringValue Get-SQLVersion.ps1 Get-Service GetSecurityDescriptor Get-Random Get-PSSnapin Get-PSSnapIn Get-PSSessionConfiguration Get-PSSession Get-PSProvider Get-PSDrive Get-PSCallStack Get-PSBreakpoint Get-PS vn ls n,17 168 167, and, class event end 524 defined, omn hiigad 30–31 and, chaining command otn n,39 and, sorting 182 153, of, output Get-Member Get-Service Get-Process $Error Get-Member Win32_Process M n,291 and, SMO 250, 249, 130, 100, 99, and, methods/properties 204 and, Method eetOjc ae VariableValue Name, Select-Object Get-Member 164 187 162 NTEventlogFile root -namespace 254 , 19 , n,67 and, 509 , , e-mOjc -class Get-WmiObject 4,24 6,20 513 280, 261, 254, 249, 524 , , , , 5 46 45, 513 524 524 , , , n,154 and, n,14 145 144, and, , , , , 8 5–5,514 153–155, 18, 4–4,514 144–146, 514 246, 163, 108, 93–94, 19, functions, n,14 145 144, and, 154 and, , , , 6 7 4,513–514 249, 97, 96, 1,1819 525 118–119, 112, 509 24, 19, 509 , , , , 3 5 6,13 6,514 164, 163, 162, 95, 53, 524 509 19, 187 n,182–183 and, , , , 287–288 193 514 94–95, 19, , , , 514 524 524 19, 513 223–224 524 19, , , | | 520 286–287 omtTbe–wrap Format-Table eetOjc Name Select-Object 2–2,434–435 224–225, , 173 , 19 , , , | | 537

Index Get-WmiObject -class (continued)

Get-WmiObject -class Win32_Process, 179 Import-Alias, 525 Get-WmiObject -class Win32_Service, 170 Import-Clixml, 525 Get-WmiObject -computerName PowerServer3 Import-Csv, 525 -class Win32_Process, 183 Import-LocalizedData, 525 Get-WmiObject -computerName PowerServer3 Import-PSSession, 525 -class Win32_Service, 170 -include , 119 Get-WmiObject -list, 163 increment (++), 50 global DBA group, 373 indexes, naming convention for, 319 global scope, 85, 87 -ine, 52 gpedit.msc, 160 infinite loop, 222, 434 graphical user interfaces. See GUIs Information (log entry type), 128 Group Policy Object Editor, 160 infrastructure, WMI, 162 Group-Object, 525 -inotlike, 52 -gt, 35, 51 -inotmatch, 52 Guest Permissions policy, 277 inputs GUIs (graphical user interfaces), command-line parameters as, 59, 60, 61 interfaces v., 1–2 Read-Host cmdlet, 58–59, 527 text files as, 62–64 installation (SQL Server 2008), 377–399 H cluster installation example, 395–399 HandleCount, 181 standalone installation example, 389–395 handling errors. See error handling template for, 381–389 Help function, 34 Install-AutoOptionsOff.ps1, 483–484 -help parameter, 79, 329 InstallDate, 186 high availability, disaster recovery and, 327–328 Install-Instance.ps1, 383–389, 397–398 hives, 190, 191 Install-MonitorBlocking.ps1, 441–443 HKEY_CLASSES_ROOT, 191 HKEY_CURRENT_CONFIG, 191 Install-MonitorDeadlock.ps1, 446–447 HKEY_CURRENT_USER, 191 Install-MonitorErrorLogsTask.ps1, HKEY_DYN_DATA, 191 437–438 HKEY_LOCAL_MACHINE, 191 Install-MonitorWindowsEventLogs.ps1, HKEY_LOCAL_MACHINESOFTWAREMicrosoftWBEM 432–433 Scripting, 163 Install-StoredProcNamingConvention HKEY_USERS, 191 Policy.ps1, 476–478 $Home, 114 Integrated Scripting Environment (ISE), 3, 11 Host snap-in, 25 Integration Services, 199, 200, 328, 378, 384, HostPerfmonDLL.sql file, 414 386, 427 hosts (SQL Server) inventory database (SQL Server), 333–376 information, SMOs and, 296 centralized inventory server, 328, 333, 409 performance data collection, 408–417 inventory database (SQL_Inventory), tables pinging, 420–423 ClusterNodes table, 350–354 SQL Server-related services and, 423–427 Clusters table, 346–350 uptime of, 427–429 Databases table, 368–373 Hosts table, 335–346 Hosts table, 335–346 CreateHosts.sql, 337–338 Servers table, 355–368 schema, 335–337 supplementary, 373–376 Upsert-Host.ps1, 341–344, 380 Invoke-Command, 509 uspUpsertHosts.sql, 338–341 Invoke-Expression, 526 Invoke-History, 115, 510 Invoke-Item, 514 I Invoke-PolicyEvaluation, 246, 278, 280, 281 -ieq, 51 Invoke-Sqlcmd, 246, 253–255 IF statement, 53–54 ISE (Integrated Scripting Environment), 3, 11 -ige, 52 -igt, 52 -ile, 52 -ilike, 52 J -ilt, 52 join clauses, 323–324 -imatch, 52 Join-Path, 515

538 itn 1–1 listing location, scope, local lusrmgr.msc, -lt, infinite, loop, - M LogFileUsage LoadWithPartialName Limit-EventLog $LastExitCode L keywords KernelModeTime, K aae resource, managed logs. monitoring, changes, login operators, logical opconstructs, loop itiifunction, list-ini IEkeyword, LIKE -like, -le, hne ihcdes 96–98 cmdlets, with change, ‘ho,’69 ‘‘throw,’’ 320 reserved, 322 LIKE, 508 EXIT, 65 63, ‘‘Error:’’, o,3,50 36, -or, 50 36, -not, 50 36, -and, 50 36, !, while for foreach do-while do-until ieo,325 of, size 329 convention, naming 329 of, format 128–134 types, entry 324 practices, best 311 308, 288, backup, 5 51 35, ann,128 Warning, 129 Audit, Success 128 Information, 129 Audit, Failure 128 Error, 5 51 35, .bat e also See 5 1 52 51, 35, op 55 loop, parameter, op 55–56 loop, 96 , CheckPowershellPreqs 3–5 ttmn,57–58 statement, 6 87 86, op 56–57 loop, op 56 loop, 160 2,434 222, vn logs event 322 20 , 54–58 , 181 50 0,407 402, 329 , 114 161 3,10 515 140, 136, , 233 1,290 210, MaximumWorkingSetSize, -match, managing ManageSQLServerService.ps1, snap-in, Management Microsoft.PowerShell.Utility, Microsoft.PowerShell.Security, Microsoft.PowerShell.Management, Microsoft.PowerShell.host, Microsoft.PowerShell.Diagnostics, Microsoft.PowerShell.core, (MMC), Console Management Microsoft irsf lseigService. Clustering Microsoft Maintenance, Practices: Best Microsoft methods. MemoryPerHost Measure-Object Measure-Command $MaximumHistoryCount MonitorErrorLog.ps1 MonitorDeadlocks.ps1 Monitor-Deadlock.ps1 MonitorDatabases.ps1 MonitorBlockings.ps1 Monitor-Blocking.ps1 Monitor-Backups.ps1 Microsoft.SqlServer.Management.Smo Microsoft.SqlServer.Management.Smo Microsoft.SqlServer.Management.Smo Microsoft.SqlServer.Management.Smo Microsoft.SqlServer.Management.Dmf models Console), Management (Microsoft MMC MinimumWorkingSetSize, Microsoft.WsMan.Management, assembly, Microsoft.SqlServer.SqlWmiManagement.dll assembly, Microsoft.SqlServer.Smo.dll aibe,11 112 111, variables, 198–203 services, Server SQL 207–211 aliases, client Server SQL 211–214 protocols, network server 98–106 files/directories, 106–107 contents, file 203–207 protocols, network client 512–519 to, related cmdlets Get-Member M oe,161–164 model, WMI 162, 161, repository, Model Information Common 161, Manager, Object Model Information Common 9,42 9,49 0,504 502, 499, 497, 492, 490, 475 0,210 209, .StoredProcedure .Server .Scripter .relocatefile 220 162 1 52 51, e loseicmethods specific also See MonitorErrorLog.ps1 class, n,9,10 3,29 5,254 250, 249, 130, 100, 99, and, class, setting, , , 526 5,20 9,33 8,488, 487, 303, 298, 290, 251, 25–26 526 , 0,47 488 487, 303, 1,314 313, 181 , , 181 6,166 165, , 25 24–25 , , , , , , 225–226 470–471 8,499 488, 27 115 2,227 226, 445–446 236 230 440–441 See 201 26 28 MSCS 27 25–26 0,290 209, 270 2,197 125, 2,197 125, , 265, 539

Index MonitorFailedLoginAttempts.ps1

MonitorFailedLoginAttempts.ps1, 234 Named Pipes protocol, 192, 193, 204, 205, monitoring (SQL Server), 419–450, 451–473 206, 211 backups, 468–472 naming conventions blockings, 229–232, 439–444 Check constraint, 320 database file growth, 461–468 columns, 319 database objects, 236–239 databases, 318 databases, 235–236 Default constraint, 320 deadlocks, 226–229, 444–449 foreign keys, 320 disk space usage, 451–460 general rules, 320 event logs, 429–433 indexes, 319 failed login attempts, 233–235 log files, 329 hosts primary keys, 320 pinging, 420–423 roles, 320 SQL Server-related services and, 423–427 script, 329 uptime of, 427–429 SQL Server standards, 318–320 login changes, 233–235 stored procedures, 318–319, 475 SQL Server error log, 225–226, 433–439 tables, 318 MonitorLogins.ps1, 233 triggers, 319 user-defined data types, 319–320 Monitor-SQLServerErrorLog.ps1, 436 user-defined functions, 319 MonitorStoredProcs.ps1, 237, 238 variables, 320, 330 Monitor_WindowsEventLogs, 438 views, 318 Monitor-WindowsEventLogs.ps1, 430–432 native commands, 16–18 more, 33 -ne, 35, 51 Move-Item, 99, 105, 515 .NET classes, 6, 209, 221, 265, 283, 521, 526 Move-ItemProperty, 515 .NET Framework MoveNext (), 114 download, 6 MSCS (Microsoft Clustering Service), 346, 348, install, 6 350, 380 SQL Server 2008 install and, 242 msdb.dbo.backupset table, 468, 469, 480 .NET-based object library, 487, 506. See also SMOs MS-DOS, 2, 3, 33 network protocols MSSQLSERVER, 171, 172, 176 client, 203–207 multiline comments, 21 server, 211–214 multi-table.ps1, 61–62 New-Alias, 526 Murphy’s law, 327 newest parameter, 132 MyDB2, 298–299 New-EventLog, 137, 138 MyDBTest, 299–304 New-Item, 99, 101, 102, 116, 117, 118, 515 compatiblity level, 302–303 New-Object, 526 differential backup, 312 New-PSDrive, 515 execute stored procedure/query, 301 New-PSSession, 510 scripting of, 303 New-Service, 515 set_RecoveryModel method and, 300, 302 New-TimeSpan, 526 transaction log backup, 311 New-Variable, 112, 116, 117–118, 526 MyDBTest2, 313, 314 New-Item v., 117–118 MyError, 69 syntax, 117 myfunction, 86 New-WebServiceProxy, 515 mymodule.ps1, 84- 85, 89 ‘‘no server access’’ condition, 265, 267, 273, 275, $mynumvar, 45 475 Myscope.ps1, 86 NODE1, 334 $mystrvar, 45 NODE2, 334 $myvar, 45, 86, 120 nonterminating errors, 67 non-uniform memory access (NUMA) nodes, 213 -not, 36, 50 -notcontains, 35 N Notepad -name parameter, 119, 154 add-num.ps1 and, 20, 21, 22 Name property, 170, 186 calculate-arith.ps1 and, 59–60 named parameters, 28–29 C:MyPsTranscripts.txt file and, 90, 91

540 OtherTransferCount, OtherOperationCount, OSName, -or, operators, logs, event operational principles, design object-oriented cmdlets, object-oriented as, DBO owner, object Editor, Object PageFileUsage, PageFaults, P Out-String Out-Printer Out-Null Out-Host Out-GridView Out-File Out-Default -option Browser, Object O Notify-WMIEvent Notepad -notmatch, -notlike, uei sinetoperators, assignment numeric nodes, access) memory (non-uniform NUMA system, file NTFS NsService, verb-, format, noun OutputVariable, OutputBuffer, output, = aibe n,4,47 45, and, variables nr,50 unary, 52 string, 50 assignment, numeric 50 logical, 51–52 comparison, read-errorlog.ps1 16 command, native emnt,185 terminate, 137 136, and, file sqlevents.txt * % / −= += rtn ofie 65–67 file, to writing 64–65 console, to writing = = = ,50 6 50 36, ,50 ,50 ,50 ,50 ,50 64–67 5 51 35, (continued) 180 5 50–52 45, , , , 200 51 527 527 526 136, 181 , 30 166 , , 527 181 30 162 , 527 526 39, 214 527 8 8 329 28, 18, 182 function, 182 321 124 44 n,63–64 and, 3,49 440 439, 435, 50 162 , 117 213 parameters, efrac aacollection data performance counters, performance performance permissions PerfRawData_Tcpip_NetworkInterface PerfRawData_PerfProc_Process PerfRawData_PerfOS_Processor PerfRawData_PerfOS_Memory Perform-PostSetupTasks.ps1 PerfMon_DB PerfDisk_PhysicalDisk -Path -passThru ParentProcessId PBM. PathName, variable, PATH aetdrcoy(..), directory parent PeakWorkingSetSize, PeakVirtualSize, PeakPageFileUsage, uptaibe 30 OutputVariable, 30 OutputBuffer, 329 and, scripts default, Q evrrltd 401–408 Server-related, SQL 408–417 host-related, 326–327 guidelines, 326 and, design database 409 401, bottlenecks, us emsin oiy 277 policy, Permissions Guest 520 and, ACLs -Path newest -name -Mail -help -full -force -detailed -desc -Debug -computerName AccessLevel -Type -recurse switches 81–84 script, oiinl 29–30 positional, 28–29 named, 30 on, information idad n,29 and, wildcards 30 WhatIf, 30 Verbose, roVral,30 ErrorVariable, 30 ErrorAction, eu,30 Debug, 415 See parameter, 0,121 102, , 154 119, , 329 , 329 79, , 33 32, , ,38 101 , 132 , 252 103, , 329 , oiyBsdManagement Policy-Based v 171 . 9 0 61. 60, 59, 79. , 0,104 103, , , 1 32 31, , 12 0,44 1,416 415, 414, 409, 181 1,215 214, , e also See 0,121 102, 6,14 7,21 208 201, 175, 164, 163, , , 97 181 181 180 7 5,12 297 182, 153, 27, e loseicparameters specific also See wthparameters switch , 0,414 409, permissions , , 0,414 409, , 392–395 117 , , 0,415 409, 415 409, , 409, 541

Index permissions (continued) permissions (continued) preference variables, 115–116 special, 325 primary keys, 320 WMI and, 159–161 Priority, 180 $PID, 114 PrivatePageCount, 181 Ping-Host function, 421–422 processes, 151–157 Ping-Hosts.ps1, 422 change priority of, 155 pinging SQL Server hosts, 420–423 cmdlets related to, 151–157, 513–514, 517–519, pipe (|), 25 522 pipelines, 30, 65. See also command chaining Debug-Process, 152, 513 plus (+) Get-Process, 18, 153–155 concatenation, 47, 49, 52 command chaining and, 30–31 unary operator, 50 Get-Member and, 154 policies, 268–281, 475–486. See also Start-Process, 152, 517, 518 SQLSERVER:SQLPolicy folder Stop-Process, 155–157, 522 ‘‘Auto_Close and Auto_Shrink Off,’’ 480–485 Wait-Process, 152, 519 ‘‘Database Auto Options Disabled,’’ 481–485 WMI and, 179–186 manual evaluation, 278–279 ProcessId, 171, 180 ‘‘Stored Procedure Naming Convention,’’ 475–480 production standards (SQL Server), 327–328 Policy class, 268, 273, 277, 278 $Profile, 115 Policy-Based Management (PBM), 259–262, $profile, 89, 115 475, 485 Profiler (SQL Server), 378 conditions and, 260, 263–268 profiles, 20, 88–90 online information, 260 %UserProfile%\Documents\WindowsPowerShell\ policies and. See policies Microsoft.PowerShell_profile.ps1, 89, 115, 224 terms in, 259 %UserProfile%\Documents\WindowsPowerShell\ Pop-Location, 96, 98, 515 profile.ps1, 88 positional parameters, 29–30 %UserProfile%\My positive (+), 50 Documents\WindowsPowerShellMicrosoft pound symbol (#), 21, 60 .PowerShell_profile.ps1, 89, 115, 224 POWERPC, 334 %UserProfile%\My Documents\WindowsPowerShell\ POWERSERVER3, 334 profile.ps1, 88 PowerShell %windir%\system32\WindowsPowerShell\v2.0\ 1.0 Microsoft.PowerShell_profile.ps1, 88 SQL Server 2008 install and, 242 %windir%\system32\WindowsPowerShell\v2.0\ uninstalling, 7 profile.ps1, 88 2.0 CTP3, 3, 7, 10 programming languages, basic requirements for, 44 coding, standards/best practices, 329–331 prompt, PowerShell, 329 installing, 7–10 properties. See also specific properties prerequisites, 2–7 Get-Member and, 99, 100, 130, 249, 250, 254 standard for, 329 providers (WMI), 161, 162. See also WMI Provider for ISE, 3, 11 Configuration Management; WMI Provider for launching, 10–13 Server Events All Programs, 11 .ps1 files, 20, 44. See also scripts command console, 11 $PSHome, 115 on SQL Server, 242–244 Push-Location, 96, 98, 516 SSMS and, 243 $pwd, 115 StartRun, 11–13 Management snap-in, 25–26 cmdlets related to, 512–519 prompt and, 329 Q purpose of, 1, 2 queries RTM, 3, 10, 151 data, 221 SDK, 18 event, 221 SQL Server and, 241–258. See also SQL Server schema, 221 SQLConnection class and, 283–290, 309 SELECT* and, 322 version, choosing, 329 Query Optimizer, 325 window, title and, 329 ‘‘quota violation,’’ 165 , 11 QuotaNonPagedPoolUsage, 182

542 ReadTransferCount, ReadOperationCount, ees omnfcuig(RTM), manufacturing to release and, WMI registry, Editor, Registry drives, registry reuse values, returning restore, -replace, Resume-Service Restore-Computer Restart-Service Restart-Computer Resolve-Path Reset-ComputerMachinePassword -replace Rename-ItemProperty Rename-Item Rename-Computer Remove-Variable Remove-PSSnapIn Remove-PSSession Remove-PSDrive Remove-PSBreakpoint Remove-Job Remove-ItemProperty Remove-Item Remove-EventLog Remove-Event Remove-Computer Register-WmiEvent -recurse Receive-Job Read-Host read-file.ps1 read-errorlog.ps1 read-errorlog2.ps1 configuration, RAID QuotaPagedPoolUsage, QuotaPeakNonP eevdkeyword, reserved Services, Reporting feature, Replication einuprSit table, RegionSupportShifts table, Regions table, RegionHolidays eoey ihaalblt and, availability high recovery, QuotaPeakPagedPoolUsage, ucin n,1,7,8,8,23 224. 223, 89, 88, 77, 19, and, functions rnato o akpadfl akp 313–316 backup, full and backup log transaction 313 backup, full cit n,4,7,440. 77, 42, and, scripts functions 313–316 52 , parameter, 7 52 47, , 85,527 58–59, , 7,375 374, , , , 510 3 108–111 93, 193 agedPoolUsage, , , 9 0,16 516 106, 105, 99, 516 104, 99, 510 80–81 , 516 516 435, 224, 223, 221, 320 190–195 , , 62 328 9,20 7,427 378, 200, 199, 379 182 , , , , , , 517 516 182 , , , 516 527 119–120, 112, 510 516 137, 516 517 7,376 374, 0,104 103, , , 517 516 510 182 , 2,22 435 222, 221, 63–64 , , , 65–66 e also See 7,375 374, 516 527 516 182 327–328 182 ,1,151 10, 3, scripts , 516 e also See scopes scripts, WMI, Library, Scripting schema(s) S rovar Script-Function.ps1 Scripter ScriptDrop Script-Db.ps1 ScriptCreate ScriptAlter scratch -scope T rlaet manufacturing), to (release RTM otIV namespace, rootCIMV2 roles, citscope, script parameters, script commands, script script of execution because loaded be cannot ‘‘script aibe 85–87 variable, 87 86, script, 87 86, local, 87 85, global, 87–88 511 function, 117, 99, 87, 86, child, ai eurmnsfr 44 for, requirements basic ikpc al,452 table, DiskSpace 321 default, 489–491 and, scripts DDL 321 dbo, DiskUsageByServer DatabaseSpace calculate-arith3.ps1 calculate-arith2.ps1 Backup-DataBase.ps1 add-num.ps1 aaae al,373 table, Databases 327 and, protection data 346 table, Clusters 351 table, ClusterNodes M,DLad 502–503 and, DDL XML, 318 and, views 318 and, tables 355–356 table, Servers 375 374, table, ServerBUContacts 375 374, table, RegionSupportShifts 375 374, table, Regions 376 374, table, RegionHolidays 221 queries, 335–337 table, Hosts euiyad 325 and, security 325 practices, best sdisabled’’, is 320 , 3 4 59 44, 43, database, 1,18 1,120 119, 118, 117, class, 6 87 86, method, method, 0 1 22 21, 20, , method, , 21 0,47 488 487, 303, 20–22 328 81–84 488–489 , al,461 table, 117 267 6,162 161, 6,13 6,10 190 170, 165, 163, 162, 267 455 , 267 , 500–501 8,290 289, , ,69–70 72 60–61, , ,1,151 10, 3, scripts 543

Index scripts (continued) scripts (continued) Ping-Hosts.ps1, 422 calculate-arith4.ps1,73–74 read-errorlog2.ps1,65–66 calculate-arith.ps1, 59–60, 80–81 read-errorlog.ps1,63–64 ChangeDefaultPortNumber.ps1, 212–213 read-file.ps1,62 ChangeStartupParameters.ps1, 216–217 reuse and, 42, 77, 440 Check-Services.ps1, 424–425 Script-Db.ps1, 488–489 Check-SqlServices.ps1, 426–427 Script-Function.ps1, 500–501 ClusterNodes table creation and, 350–351 Script-Schema.ps1, 490–491 Collect-HostPerfmon.ps1, 414–416 Script-SP.ps1, 498–499 Collect-SQLPerfmonData.ps1, 406–407 Script-Table.ps1, 494–496 command shell and, 22–23 Script-UDDtype.ps1, 491–492 CreateDatabases.ps1, 368–369 Script-UDtype.ps1, 492–493 CreatePolicy.ps1, 273–275 Script-User.ps1, 503–504 CreateServerAlias2008.ps1, 211 Script-View.ps1, 497 Create-Servers.ps1, 356 Script-XMLSchema.ps1, 502 DDL, 487–506 Test-Args1.ps1,81 databases, 487–489 Test-Args2.ps1,82 functions, 500–501 Test-Args3.ps1,83–84 schemas, 489–491 test-trap.ps1,70–71 stored procedures, 498–500 Update-DiskSpace.ps1, 456–459 tables, 494–496 Update-SQLServerHosts.ps1, 428 user views, 496–498 Upsert-ClusterNode.ps1, 353–354 user-defined data types, 491–494 Upsert-Cluster.ps1, 348–350 users, 503–506 Upsert-Database.ps1, 370–373 XML schemas, 502–503 Upsert-Host.ps1, 341–344, 380 default parameters, 329 Upsert-Server.ps1, 361–368 DeleteClientAlias.ps1, 209 Script-Schema.ps1, 490–491 DisableListenOnAllIPs.ps1, 213–214 Script-SP.ps1, 498–499 EnableFileStream.ps1, 215 Script-Table.ps1, 494–496 FunctionScope.ps1,87–88 Script-UDDtype.ps1, 491–492 Get-SQLVersion.ps1, 286–287 Script-UDtype.ps1, 492–493 Get-Tables.ps1, 287–288 Script-User.ps1, 503–504 Get-WMIEvent.ps1, 223–224 Script-View.ps1, 497 Install-AutoOptionsOff.ps1, 483–484 Script-XMLSchema.ps1, 502 Install-Instance.ps1, 383–389, 397–398 SDK (Software Development Kit), 18 Install-MonitorBlocking.ps1, 441–443 security Install-MonitorDeadlock.ps1, 446–447 best practices, 325 Install-MonitorErrorLogsTask.ps1, DCOM, 160 437–438 roles and, 325 Install-MonitorWindowsEventLogs.ps1, Security event log, 128 432–433 Security snap-in, 26 Install-StoredProcNamingConvention cmdlets related to, 519–520 Policy.ps1, 476–478 segregation, 328 Monitor-Backups.ps1, 470–471 SELECT*, 322 Monitor-Blocking.ps1, 440–441 Select-Object, 34, 37, 95, 100, 165, 166, 168, MonitorBlockings.ps1, 230 172, 187, 198, 203, 204, 206, 263, 528 Monitor-Deadlock.ps1, 445–446 Select-String, 528 MonitorDeadlocks.ps1, 226, 227 Send-Email function, 420–421 MonitorErrorLog.ps1, 225–226 Send-MailMessage, 528 MonitorFailedLoginAttempts.ps1, 234 Serialize method, 270, 271, 272 MonitorLogins.ps1, 233 server components (SQL Server), 378 Monitor-SQLServerErrorLog.ps1, 436 Server Events. See WMI Provider for Server Events Monitor-WindowsEventLogs.ps1, 430–432 server events classes, 220 multi-table.ps1,61–62 Server Management Objects. See SMOs mymodule.ps1, 84–85, 89 server network protocols, 211–214 Myscope.ps1,86 ServerBUContacts table, 374, 375 naming convention, 329 ServerNetworkProtocolProperty class, 211, Perform-PostSetupTasks.ps1, 392–395 212, 213, 393, 394

544 SMO.BackupDeviceitem SMO.Backup SilentlyContinue Show-EventLog Set-Variable Set-TraceSource SetStringValue Set-StrictMode SetStartMode Set-Service SetSecurityDescriptor set_RecoveryModel Set-PSDebug Set-PSBreakpoint SetPriority Set-Location Set-ItemProperty Set-Item Set-ExecutionPolicy Set-Date Set-Content Set-AuthenticodeSignature Set-Alias Set-Acl ON NOCOUNT SET table, Servers ie aaaelgfile, database/log size, hl functions. shell SetX.exe, evcs(Windows), services Server), (SQL services Broker, Service Ms(evrMngmn Objects), Management (Server SMOs cea 355–356 schema, uspUpsertServers Upsert-Server.ps1 Create-Servers.ps1 M n,170–179 and, WMI 143–151 to, related cmdlets 200 199, types, 200 states, 203 modes, start ‘‘ 304–308 and, tables 290–297 and, Server SQL 313–316 with, restore D cit n,487. and, scripts DDL 297–304 and, databases 290 library, class 308–313 with, backup TestDatabase eso nomto,291–292 information, version 292 information, SPID 293–294 information, server-related 291 properties/methods, 297 counters, performance 296 information, host 295 information, database-related 296 mode, login change , 122 520 , , 2,517 121, 528 , 528 355–368 class, , , , , See 2,259 220, , , , 5–5,517 150–151, 511 75, 74, 73, 72, 71, 183–185 517 107, 106, 89, 66, 65, , , 1,19 529 119, 112, 203 202, 517 97, 96, 22, 21, 2,44 1,463 415, 404, 323, , 3,17 3,10 1,517 513, 140, 138, 137, 136, ’ad 251–252 and, ’’ method, functions , 141–151 511 309 , , , 529 198–203 5 1,116 115, 75, 528–529 517 325 e also See method, trdpoeue 357–361 procedure, stored 361–368 , , 356 , 2 6 520 26, 22, class, 194 , 173 D scripts DDL 0,302 300, , 309 520 0,290–316 209, sorting, (SDK), Kit Development Software sourcing, Q Server SQL item), (child SQL Split-Path sp_configure -Source Sort-Object sp_trace_setstatus sp_trace_setevent snap-ins, sa.aaeet 28 WsMan.Management, 27 Utility, 242 241, Server, SQL 26 Security, 25–26 Management, 25 Host, 27 Diagnostics, 24–25 Core, 260–261 and, dbaLib.ps1 adding, oioig 1–5,451–473 419–450, monitoring, 242–245 on, PowerShell launching ofiuainMngr 8,17 1,378. 218, 197, 185, Manager, Configuration 379 tools, client 207–211 aliases, client 378 Studio, Development Intelligence 479 Business 216, 200, 199, service, Browser 255 254, authentication, 378 200, 199, Services, Analysis 200, 199, 178, 177, 176, 173, 148, service, Agent 216–218 changing, properties, advanced 2008. netr database. inventory 384, 378, 328, 200, 199, Services, Integration 377–399 installation, 433–439 hosts 225–226, monitoring, log, error 318–320 standards, development 323 types, data date/datetime 378 Advisor, Tuning Engine Database 378 Components, Connectivity mlt eae o 520–530 to, related cmdlets 519–520 to, related cmdlets 512–519 to, related cmdlets 507–511 to, related cmdlets aaaeojcs 236–239 objects, database 439–444 229–232, blockings, ntlain 377–399 installation, 378 editions, epaefr 381–389 for, template 389–395 example, installation standalone 395–399 example, installation cluster 408–417 collection, data performance 296 and, SMOs information, 0,33 8,36 9,397 391, 386, 384, 383, 203, 8,427 386, Management Configuration for Provider WMI 38–39 e also See 32,241 23–28, 84–85 option, , 517 , , 0 1 83,529 38–39, 31, 30, 247 installation 138 2,20 294 260, 229, See , , 233 netr database inventory 233 18 Q Server SQL e also See 545

Index SQL Server (continued)

SQL Server (continued) standalone installation example (SQL Server 2008), databases, 235–236 389–395 deadlocks, 226–229, 444–449 Perform-PostSetupTasks.ps1, 392–395 error log, 225–226, 433–439 template file for, 389–391 event logs, 429–433 StandaloneTemplate.txt, 389–391 failed login attempts, 233–235 Standard edition, 378, 379 login changes, 233–235 standards, 317–331 performance data collection, 401–408 best practices and, 317 PowerShell and, 241–258 data protection, 327 PowerShell provider, 242 database design, 324–327 restrictions of, 250 PowerShell coding, 329–331 production standards, 327–328 SQL Server, 318 Profiler, 378 development, 318–320 Reporting Services, 199, 200, 378, 427 production, 327–328 segregation and, 328 stored procedure, 321–324 server components, 378 Start Run, PowerShell and, 11–13 SMOs and, 290–297 Started, 171 change login mode, 296 Start-Job, 511 database-related information, 295 StartMode property, 171 host information, 296 StartName, 172 performance counters, 297 Start-Process, 152, 517, 518 properties/methods, 291 StartService, 173, 174 server-related information, 293–294 Start-Service, 148–149, 518 SPID information, 292 Start-Sleep, 529 version information, 291–292 Start-Transaction, 518 snap-ins, 241, 242 Start-Transcript, 25, 90, 91 standards, 318 static classes, 162 traces, 233 Status property, 171 SQL Server Management Studio (SSMS) StdRegProv, 190, 191, 192, 193 launching PowerShell through, 243 Step, 71, 511 query window, 216, 226, 230, 231, 233, 236, 237, Stop-Computer, 518 443, 444, 447, 448 Stop-Job, 511 SQL Server-related services, hosts and, 423–427 Stop-Process, 155–157, 518, 522 SQL2008CLUSTER, 334, 350, 354, 380, 395, 397, StopService, 173 398 Stop-Service, 146–148, 518 SQLCommand class, 284 Stop-Transcript, 25, 90, 91 SQLConnection class, 283–290, 309 ‘‘_stored procedure_’’, 499 SQLDataAdapter class, 284 ‘‘Stored Procedure Naming Convention’’ policy, sqlevents.txt file, 136, 137 475–480 sqlevents.xml file, 135 stored procedures SQL_Inventory. See inventory database comments and, 321–322 SQLPerfmonDDL.sql file, 406 cursors and, 322 sqlps utility, 241–245 dba_MonitorBackups, 479, 480 SQLRegistration, 247, 248 DDL scripts and, 498–500 SQLRestore(), 313, 314 naming conventions for, 318–319, 475 SQLSERVER: drive, 241, 245, 246, 256, 258, 259, SELECT* and, 322 260, 261, 283 small, 321 child items, 247 standards, 321–324 SQLSERVERAGENT, 173, 174, 175, 176, 177, 203 temporary tables and, 322 SqlServerAlias class, 208, 209, 211 ‘‘usp’’ and, 318, 475 SqlServerCmdletSnapin100, 245, 246 uspMonitorBackups, 468–469 SqlServerProviderSnapin100, 245, 246 uspUpsertClusterNodes, 351, 353 SQLSERVER:SQLPolicy folder, 247, 259–262 uspUpsertClusters, 347 SqlService class, 198, 212, 216, 427 uspUpsertDatabases, 369 SqlServiceAdvancedProperty class, 216, 217, uspUpsertDatabaseSpace, 462 218 uspUpsertDiskspace, 453 SQLservr.exe, 172, 179, 180, 182, 184 uspUpsertHosts, 338 SSMS. See SQL Server Management Studio string operators, 52

546 syntax wthparameters, switch svchost.exe, wthstatement, switch switches ‘‘_table_’’ T sys.dm_os_schedulers sys.dm_os_performance_counters sys.dm_os_memory_clerks sys.dm_exec_sql_text sys.dm_exec_query_stats Suspend-Service database), (inventory tables supplementary type), entry (log Audit Success SystemVariable, SystemName, log, event System tables mlt 28–31 cmdlet, upeetr ivnoydtbs) 373–376 database), (inventory supplementary 304–308 and, SMOs 355–368 table, Servers 375 374, ServerBUContacts, 318 and, schema 375 374, RegionSupportShifts, 375 374, Regions, 376 374, RegionHolidays, 318 for, convention naming parameters 79 as, arguments Test TaskCount msdb.dbo.backupset LogFileUsage DiskSpace DatabaseSpace AWEAllocated New-Variable -WhatIf -unique -confirm WulVrin 243 AWBuildVersion, aaae al,368–373 table, Databases 305 creating, columns 346–350 table, Clusters 350–354 table, ClusterNodes ot al,335–346 table, Hosts 308 dropping, eprr,322 temporary, D cit n,494–496 and, scripts DDL eoig 306–307 removing, 305–306 listing, 307–308 adding, 2,21 3,30 4,48 449 448, 444, 330, 232, 231, 227, , , 496 1,16 157 146, 116, , 168 166, 165, , 0 3,17 4,19 5,157 156, 149, 148, 147, 137, 30, , 125 v 2–5,467–468 425–454, , 0,407 402, , 172 . ,79 186 0,407 402, , 407 402, , 117 , 128 53 461–468 , 83 , 518 6,49 480 469, 468, , , , 404 404 129 , , 404 404 , 404 373–376 taskmgr, emntn errors, terminating akScheduler Task targets, sets, target C/Pports, TCP/IP ‘‘ epae(Q evrinstallation), Server (SQL template etfiles, text eprr tables, temporary tempdb Tee-Object TCP/IP TaskMgr TaskCount -Type TRY $True TRAP object Transfer Trace-Command Trace ToUpper TopQueries TopMemConsumption TextData test-trap.ps1 Test-Path Test-Connection Test-Args3.ps1 Test-Args2.ps1 Test-Args1.ps1 Test2 Test Terminate triggers, ‘ho’ keyword, ‘‘throw’’ ThreadCount, -Q omn (example), command T-SQL transcripts, backup, log transaction traces, editors, text TestDatabase srdfie,324 user-defined, 70,26 0,28 1,35 399 395, 210, 208, 207, 206, #7001, 213 212, #3660, 212 206, 193, #1433, eprr alsad 322 and, tables temporary 325 split, 327 and, backup TopQueries TopMemConsumption Test2 Install-Instance.ps1 block, 6,38 385 368, 367, , table, 70–71 , , parameter, table, 233 115 511 73, 72, 71, 259 2,48 449 448, 227, , protocol, 319 151 , 62–64 method, 151 323 property, 90–91 5,260 259, , , , 2,21 3,30 4,48 449 448, 444, 330, 232, 231, 227, 21. 0,407 402, 519 185–186 183, , , 2,48 449 448, 227, 181 6,41 7,481 476, 441, 368, 529 0,407 402, 0,407 402, , .,124 2.0, e also See ’’, , , 322 9,24 0,26 1,212, 210, 206, 205, 204, 192, 69 101 46 67 , , , 529 70–71 , 251–252 , 83–84 82 81 2,2829 231 228–229, 227, 505 519 , 8,38 311 308, 288, 0,407 402, 0,407 402, , -Type Notepad 286–287 383–389 , 381–389 parameter 547

Index ‘‘_udtype_’’ U V ‘‘_udtype_’’, 494 -valueOnly , 119 unary operators, 50 values, returning, 80–81 Undo-Transaction, 519 varbinary (max), 214, 326 Uniform Resource Name (URN), 256–258 variable drives, 88, 93, 111, 121 -unique switch parameter, 165, 166, 168 variable scope, 85–87 Unregister-Event, 221, 223, 224, 435 variables, 44–47. See also specific variables Update-DiskSpace.ps1, 456–459 automatic, 113–115 Update-FormatData, 529 date values and, 47 Update-List, 529 dollar symbol and, 45 Update-SQLServerHosts.ps1, 428 environment, 93, 121–122 Update-TypeData, 529–530 WMI and, 186–189 Upsert-ClusterNode.ps1, 353–354 equals operator and, 45, 47 Upsert-Cluster.ps1, 348–350 managing, with cmdlets, 111, 112 Upsert-Database.ps1, 370–373 naming convention for, 320, 330 Upsert-Host.ps1, 341–344, 380 preference, 115–116 Upsert-Server.ps1, 361–368 user-created, 116–120 URN (Uniform Resource Name), 256–258 VariableValue, 186 ‘‘_user_’’, 504 VBScripts, 2, 18, 162 user profiles. See profiles VCS (Veritas Cluster Server), 348 user views, DDL scripts and, 496–498 verb-noun format, 18, 28, 329 user-created variables, 116–120 Verbose, 30 user-defined data types, 319–320 Veritas Cluster Server (VCS), 348 DDL scripts and, 491–494 versions user-defined functions, 319 PowerShell, 329 user-defined tables, 324 SQL Server, SMOs and, 291–292 UserModeTime, 181 ‘‘_view_’’, 498 UserName, 186 views %UserProfile%\Documents\WindowsPowerShell\ DMVs, 404, 417 Microsoft.PowerShell_profile.ps1, 89, 115, 224 naming convention for, 318 %UserProfile%\Documents\WindowsPowerShell\ schema and, 318 profile.ps1, 88 VirtualSize, 182 %UserProfile%\My Documents\WindowsPowerShell\ Microsoft.PowerShell_profile.ps1, 89, 115, 224 %UserProfile%\My W Documents\WindowsPowerShell\profile.ps1, 88 Wait-Job, 511 users, DDL scripts and, 503–506 Wait-Process, 152, 519 Use-Transaction, 519 Warning (log entry type), 128 ‘‘usp,’’ 318, 475. See also stored procedures $WarningPreference, 116 uspBackupDB, 288–289 wbemtest.exe, 165 uspMonitorBackups stored procedure, 468–469 Web edition, 378 uspUpsertClusterNodes stored procedure, 351, wevutil, 124 353 WhatIf, 30 uspUpsertClusterNodes.sql, 351–353 -WhatIf switch parameter, 116, 146 uspUpsertClusters stored procedure, 347 $WhatIfPreference, 116 uspUpsertClusters.sql, 347–348 Where-Object, 25, 30, 31, 34, 35, 100, 119, uspUpsertDatabases stored procedure, 369 132, 511 uspUpsertDatabaseSpace stored procedure, 462 while loop, 55–56 uspUpsertDatabaseSpace.sql, 462–463 wildcards uspUpsertDatabases.sql, 369–370 *, 100 uspUpsertDiskspace stored procedure, 453 ?, 101 uspUpsertDiskspace.sql, 453–454 [, ], 101 uspUpsertHosts stored procedure, 338 parameter values and, 29 uspUpsertHosts.sql, 338–341 Win32_Environment, 186, 187, 189 uspUpsertServers stored procedure, 357–361 Win32_LogicalDisk, 95, 162, 163, 453, 457 Utility snap-in, 27 Win32_NTEventlogFile, 163, 164 cmdlets related to, 520–530 Win32_NTLogEvent, 163, 165, 166, 167, 168, 169

548 M WnosMngmn Instrumentation), Management (Windows WMI Management), Remote (Windows WinRM idw aaeetInstrumentation. Management , Windows idw services. Windows (WinRM), Management Remote Windows WindowsVersion Win32_Service Win32_Process Win32_PerfRawData_Tcpip_ Win32_PerfRawData_PerfProc_Process Win32_PerfRawData_PerfOS_Processor Win32_PerfRawData_PerfOS_Memory Win32_PerfRawData_PerfDisk_ idw vn logs. event Windows calculator, Windows %windir%\system32\WindowsPowerShell\v2.0\ %windir%\system32\WindowsPowerShell\v2.0\ idw processes. Windows idw PowerShell. Windows classes. 162 Studio, CIM Terminate SetPriority Get-Process ttcpoete,179–180 properties, static 181–182 properties, memory-related 182 properties, related I/O rpris 170–172 properties, 173 methods, 181 properties, CPU-related rvdr,11 162 161, providers, 179–186 and, processes 159–161 and, issues permission 162 Browser, Object 161–164 model, 161 resource, managed 162 infrastructure, 159 of, importance 162 125, Viewer, Event 162 Tool, Registration Event 164–170 and, logs event 186–189 and, variables environment 160 and, security DCOM 162 consumer, 159–195 profile.ps1, Microsoft.PowerShell_profile.ps1, NetworkInterface PhysicalDisk See n,13 185–186 183, and, classes 88 n,183–185 and, 182–183 and, , , 6,368 160, See , 6,170–179 163, 179–186 163, 180 17 See See , See 414 services processes vn logs event PowerShell , 414 88 See 6–7 6–7 , 414 WMI , , 95, 414 414 M ur Language. Query WMI M cea,DLsrpsand, scripts DDL schemas, XML WriteOperationCount, WriteTransferCount, M rvdrfrSre Events, Server for Provider WMI M rvdrfrCngrto Management, Configuration for Provider WMI Q WIQeyLanguage), Query (WMI WQL WorkingSetSize, edition, Workgroup Provider, Installer Windows WMI ‘‘_xml_’’ X Write-Warning Write-Verbose Write-Progress Write-Output Write-Host Write-EventLog Write-Error Write-Debug sa.aaeetsnap-in, WsMan.Management Ws-Management, writing M cea,DLsrpsand scripts DDL schemas, XML Q n,220–221 and, 225–226 WQL and, log error Server SQL 219–220 overview, 239 information, online 233 and, changes login 233–235 and, attempts login failed 221–225 and, handling event 226–229 and, deadlocks 236–239 and, monitoring object database 235–236 and, monitoring database 229–232 and, blockings Q evrsrie n,198–203 and, services Server 207–211 SQL and, aliases client Server 216–218 SQL and, properties advanced Server SQL 211–214 and, protocols network server 214–216 and, FILESTREAM 203–207 and, protocols network client idw iealstig n,160 and, settings Firewall Windows 170–179 and, services 162 161, Library, Scripting 190–195 and, registry ofie 65–67 file, to 64–65 console, to 197–218 , 503 , 8 9 0 1 2 4 5 7,530 473, 65, 64, 62, 61, 60, 59, 28, , , , 530 530 75, 73–74, 181 , , 6–7 4 5 7,530 473, 65, 64, , , 530 530 378 182 530 519 182 See WQL 220–221 28 9,219–240 197, 502–503 5 549

Index