Share this Post

Jeong's Blog

Recent Posts

This document explains how to specify the values of parameter values and how the configuration file is updated by IIS Powershell generic cmdlets such as Get-WebConfiguration and Get-WebConfigurationProperty so that users can use them effectively.

I'd like to inform that the configuration editor of IIS8 has an useful feature to generate IIS Powershell cmdlets. You can use that feature if you want to get the example usage quickly.

Examples how to use parameter values

-PSPATH

COMMAND Examples:-PSPATH is used to specify the target web object such as server/site/web application/virtual directory and physical directory. The following examples show that there are two equivalent type of PSPATH

## Using the path form which is used by MWA and you can specify MACHINE or MACHINE/WEBROOT level as well in this form; The "MACHINE/WEBROOT/APPHOST" is equivalent to "IIS:\", which is another form of PSPATH

## Even -pspath parameter don't need to be specified if the current directory location is changed to that place

Cd'IIS:\Sites\Default Web Site\webapplication1'

Get-WebConfigurationProperty -filter $filter -name $propertyName

TIP

For server level configurations such as config section which starts with system.applicationhost, we can skip to specify the pspath parameter also

-Filter

COMMAND Examples:-Filter can be xpath form to specify a specific or multipleitems 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 equivalentin 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

## Specify a certain node with substring-after() function to say that the node name should containsa 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 containsa 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

You might be confused if you use the -recurse parameter from child level and you got no result. For the example, if you enablebasicAuthentication on Default Web Site and run the following command, you will get empty result. This is because the authentication setting is actually configured in the server level configuration file such as applicationhost.config using location tag of "<location path="Default Web Site">".

If the authentication setting was configured in the web.config of Default Web Site's root directory after delegating the authentication configuration to site level, both of the above two commandswill work because the actual configuration is now set in the Default Web Site level.

-Value

COMMAND Examples:When -Valueparameter is used by IIS powershell cmdlet, it usually set with a single string value (NOTE: if the value contains space, it should be quoted with " or ')

## The value can be hash table object if it is used to set a collection item