The SQL Server Management Object (SMO) models and SQL Server PowerShell snap-ins use two types of expression strings that are similar to XPath expressions. Query expressions are strings that specify a set of criteria used to enumerate one or more objects in an object model hierarchy. A Unique Resource Name (URN) is a specific type of query expression string that uniquely identifies a single object.
For example, specify Server for the ServerCollection class, Database for the DatabaseCollection class.
Specifies the name of one of the properties of the class that is associated with the object specified in Object. The name of the property must be prefixed with the @ character. For example, specify @IsAnsiNull for the Database class property IsAnsiNull.
Enumerates all objects where the specified Boolean property is set to TRUE.
Enumerates all objects where the specified Boolean property is set to FALSE.
Enumerates all objects where the specified string property contains at least one occurrence of the set of characters that is specified in 'PatternString'.
Enumerates all objects where the value of the specified string property is exactly the same as the character pattern that is specified in 'PatternString'.
Enumerates all objects where the value of the specified date property matches the date that is specified in 'DateString'. DateString must follow the format yyyy-mm-dd hh:mi:ss.mmm
Four digit year.
Two digit month (01 through 12).
Two digit date (01 through 31).
Two digit hour using a 24 hour clock (01 through 23).
Two digit minutes (01 through 59).
Two digit seconds (01 through 59).
Number of milliseconds (001 through 999).
The dates that are specified in this format can be evaluated against any date format that is stored in SQL Server.
Enumerates all objects where the specified property has a value of NULL.
Negates the evaluation value of the PropertyExpression, enumerating all objects that do not match the condition specified in PropertyExpression. For example, not(contains(@Name, 'xyz')) enumerates all objects that do not have the string xyz in their names.
Query expressions are strings that enumerate the nodes in an SMO model hierarchy. Each node has a filter expression that specifies the criteria for determining which objects at that node are enumerated. Query expressions are modeled on the XPath expression language. Query expressions implement a small subset of the expressions that are supported by XPath, and also have some extensions that are not found in XPath. XPath expressions are strings that specify a set of criteria that are used to enumerate one or more of the tags in an XML document. For more information about XPath, see W3C XPath Language.
Query expressions must start with an absolute reference to the Server object. Relative expressions with a leading / are not allowed. The sequence of objects that are specified in a query expression must follow the hierarchy of collection objects in the associated object model. For example, a query expression that references objects in the Microsoft.SqlServer.Management.Smo namespace must start with a Server node followed by a Database node, and so on.
If a <FilterExpression> is not specified for an object, all the objects at that node are enumerated.
Unique Resource Names (URN)
URNs are a subset of query expressions. Each URN forms a fully-qualified reference to a single object. A typical URN uses the Name property to identify a single object at each node. For example, this URN refers to a specific column: