Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

775


Chapter 30: Confi guring and Managing SQL Server with PowerShell


30


To help with logic fl ow, PowerShell provides a group of “object” cmdlets, as shown in Table 30-2.

TABLE 30 -2 Object Cmdlets in PowerShell

Cmdlet Alias Description
ForEach-Object % Executes once for each member in the collection
Where-Object? Filters objects based on conditions
Select-Object select Pipes only the specifi ed properties
Sort-Object sort Sorts the objects
Tee-Object tee Sends the objects in two directions

In the earlier example of the $servers collection, the collection can be iterated through
using the following commands:

$servers | Foreach-Object {
Write-Output $_
}

These cmdlets are useful when scripting. For example, they enable iteration through a col-
lection of properties in objects, as shown here:

get-service | where-object {$_.Status -eq "Running"}

The preceding produced the following results:

Status Name DisplayName
------ ---- -----------
Running 1-vmsrvc Virtual Machine Additions Services ...
Running AeLookupSvc Application Experience Lookup Service
Running Browser Computer Browser
Running CryptSvc Cryptographic Services
Running DcomLaunch DCOM Server Process Launcher
Running Dhcp DHCP Client
Running dmserver Logical Disk Manager
Running Dnscache DNS Client
Running ERSvc Error Reporting Service
Running Eventlog Event Log
Running EventSystem COM+ Event System
Running helpsvc Help and Support
Running HTTPFilter HTTP SSL
Running lanmanserver Server
Running lanmanworkstation Workstation
Running LmHosts TCP/IP NetBIOS Helper
Running MSDTC Distributed Transaction Coordinator
Running MsDtsServer100 SQL Server Integration Services 10.0
Running MSOLAP$INST01 SQL Server Analysis Services (INST01)

c30.indd 775c30.indd 775 7/31/2012 9:46:21 AM7/31/2012 9:46:21 AM


http://www.it-ebooks.info
Free download pdf