Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

774


Part V: Enterprise Data Management


Referencing the $servers collection, each element in the collection is a string object, and
string objects have a Length property, so the element can be tested to determine whether
it has a value using the following commands:

if ($servers[0].Length -gt 0) {
#work
}

Control fl ow is handled by the commands shown in Table 30-1.

TABLE 30 -1 Control Flow Commands

Command Example
I f if ($val -eq “target”) {
#work
}
For For ($i=0; $i -lt 10; $i++) {
#work
}
Switch Switch ($val) {
“Val1” {
#work
}
“Val2” {
#work
}
}
Do Until Do {
#work
}
Until ($val -eq “target”)
Do While Do {
#work
}
While ($val -eq “target”)
While While ($val -eq “target”) {
#work
}

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


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