|
COMMAND Examples: -Filter can be xpath form to specify a specific or multiple items of IIS config object such as element/collection/attribute; It will be very useful for you to know various xpath style value to enumerate IIS configurations.
## Specify a site element section with xpath style value
$filter = "//sites/site"
$propertyName = "id"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a site element section with full path value
$filter = "system.applicationHost/sites/site"
$propertyName = "id"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Enumerating site (NOTE: the following five xpath examples are equivalent in IIS config file and shows that you can use wild card value. FYI, "." means a collection item, which can be optional for specifying collection items)
Get-WebConfiguration -filter /system.applicationHost/sites/site
Get-WebConfiguration -filter /system.applicationHost/sites/site/.
Get-WebConfiguration -filter /*/*/site
Get-WebConfiguration -filter //sites/site
Get-WebConfiguration -filter //*/sites/site
## Enumerating name attribute of site (NOTE: the following two xpath examples are equivalent)
Get-WebConfiguration -filter /system.applicationHost/sites/site/@name
Get-WebConfiguration -filter //sites/site/@name
Get-WebConfiguration -filter //sites/site/./@name
## Specify a certain site node with filtering with multiple attribute values
$filter = "/system.applicationHost/sites/site[@name='Default Web Site' and @id='1']"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with a single attribute value
$filter = "/system.applicationHost/sites/site[@name='Default Web Site']"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with contains() function to say that its attribute "name" should contain a specific string
$filter = "/system.applicationHost/sites/site[contains(@name,'Default')]"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with last() function to say that its attribute "name" should end with a specific string
$filter = "/system.applicationHost/sites/site[last(@name,'Site')]"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with starts-with() function to say that its attribute "name" should start with a specific string
$filter = "/system.applicationHost/sites/site[starts-with(@name,'Default')]"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with position() function to say it should be placed at first
$filter = "/system.applicationHost/sites/site[position()=1]"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with count() to say that its parent should have only one site node
$filter = "//*[count(site)=1]/site"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with name() to say that the element name should be "site"
$filter = "//*[name()='site']"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with local-name() to say that the element name should be "site"
$filter = "//*[local-name()='site']"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with starts-with() function to say that the element name should start "site" should end with a specific string
$filter = "//*[starts-with(name(),'site')]"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with concat() function to say that the combined string of name and id attributes should be a specific string, "Default Web Site1", which is "Default Web Site" + "1"
$filter = "/system.applicationHost/sites/site[concat(@name, @id)='Default Web Site1']"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain node with substring-after() function to say that the node name should contains a specific string such as "site"
$filter = "//*[substring-after(name(), 'site')]"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain node with substring-before() function to say that the node name should contains a specific string such as "ite"
$filter = "//*[substring-before(name(), 'ite')]"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain node with substring function to say that the node name's substring start 0th with length 2 should be a specific string such as "si"
$filter = "//*[substring(name(),0,2)='si']"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain node with string-length() function to say that the legnth of the node name should be 4
$filter = "//*[string-length(name())=4]"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain node with string-length() function to say that the legnth of the node name should be 4
$filter = "//*[string-length(name())=4]"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with translate() function to say that its name attribute value should be "default web site" if "D" in the original string is replaced with "d", "W" with "w", and "S" with "s" as well
$filter ="/system.applicationHost/sites/site[translate(@name, 'DWS', 'dws')='default web site']"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with compare-string-ordinal() function to say that its name attribute should be "default web site" in comparing case-in-sensitively
$filter ="/system.applicationHost/sites/site[compare-string-ordinal(@name,'default web site',true())=0]"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with compare-string-ordinal() function to say that its name attribute should be "Default Web Site" in comparing case-in-sensitively
$filter ="/system.applicationHost/sites/site[compare-string-ordinal(@name,'Default Web Site',false())=0]"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Specify a certain site node with compare-string-ordinal() function to say that its name attribute should be "Default Web Site" in comparing case-in-sensitively
$filter ="/system.applicationHost/sites/site[compare-string(@name,'Default Web Site',true())=0]"
Get-WebConfigurationProperty -filter $filter -name $propertyName
## Using "and" and "or" for set multiple condition using contains() function
$filter='/system.webServer/handlers[(contains(@accessPolicy, "Script") and contains(@accessPolicy, "Write")) or (contains(@accessPolicy, "Execute") and contains(@accessPolicy, "Write"))]'
Get-WebConfiguration -filter $filter -recurse
## following xpath functions are also supported:
Normalize-space(), Boolean(), Not(), Number(), Sum(), Floor(), Ceiling(), Round() and Compare-string() |