Databases Reference
In-Depth Information
TABLEĀ 14-3
(continued)
OPERATOR
DESCRIPTION
-notlike
Does not match using the (*) wildcard
character
-match
Matches a string using a regular
expression
-notmatch
Does not match a string using a
regular expression
-contains
Includes an identical value
-notcontains
Does not include an identical value
-band
Bitwise AND
-bor
Bitwise OR
-bxor
Bitwise XOR
It is often useful to know the makeup of a variable. You can discover the structure of an object using
the
Get-Member
cmdlet. The following code demonstrates the creation of a new string object and
then passing it into the
Get-Member
cmdlet:
PS > [String]$NewString | Get-Member
Knowing the members available on an object is very useful because you can start using them. For
instance, in the following example I have a Statement string and want to return the last word. By
inspecting the members on the
$Statement
variable, I can see that there is a
Length
property, an
IndexOf
method, and a
Substring
method, which I can use together to return the part of the string
I'm interested in (code i le:
PS_StringManipulation01.PS1
):
$Statement = "PowerShell Rocks"
$Statement.SubString($Statement.IndexOf(" ") + 1, $Statement.Length -
$Statement.IndexOf(" ") - 1)
Advanced Functions
Once you have used a snippet of PowerShell code a few times you'll probably want a way of refac-
toring that code into something that you can reuse easily. Fortunately, PowerShell 2.0 makes this
very easy to accomplish with a new feature called
advanced functions
. I'm going to use a trivial
example to demonstrate this functionality. Assume that you regularly i lter the
Get-Process
cmdlet for all processes starting with SQL, and you want to be able to return all these processes
with a simple cmdlet named
Get-SQLProcess
. The following code listing shows how this advanced
function is created:
Search WWH ::
Custom Search