Edit

Share via


New-IISConfigCollectionElement

Creates a new configuration element object in an IIS configuration collection.

Syntax

Default (Default)

New-IISConfigCollectionElement
    [-ConfigCollection] <ConfigurationElementCollection>
    [-ConfigAttribute] <Hashtable>
    [[-AddAt] <UInt32>]
    [-Passthru]
    [<CommonParameters>]

Description

The New-IISConfigCollectionElement cmdlet creates a new ConfigurationElement in a given Internet Information Services (IIS) ConfigurationCollection.

Examples

Example 1: Add a new file name to list of default documents

PS C:\> $ConfigSection = Get-IISConfigSection -SectionPath "system.webServer/defaultDocument"
PS C:\> $DefaultDocumentCollection = Get-IISConfigCollection -ConfigElement $ConfigSection -CollectionName "files"
PS C:\> New-IISConfigCollectionElement
  -ConfigCollection $DefaultDocumentCollection -ConfigAttribute @{"Value" = "MyDefDoc.htm"}

This command creates an entry in the list of default documents.

Example 2: Add a new file name to the top of the list of default documents

PS C:\> Get-IISConfigSection -SectionPath "system.webServer/defaultDocument" | Get-IISConfigCollection -CollectionName "files" | New-IISConfigCollectionElement  -ConfigAttribute @{Value = "MyDefDoc.htm"} -AddAt 0

This command creates a new entry in the list of default documents, and makes this new entry the first item in the collection. This is done by setting the value of the AddAt parameter to 0; the first item in a collection is always item number 0.

Parameters

-AddAt

Specifies the collection index for the new configuration element; by default, new elements are added to the end of the collection. The collection index specifies the ordering of items in the collection: the first item in the collection is item 0; the second item in the collection is item 1; and so on.

Parameter properties

Type:UInt32
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:3
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ConfigAttribute

Specifies a hashtable of the attributes for the configuration element to be inserted. The cmdlet will fail if any required attributes are omitted from this table.

Parameter properties

Type:Hashtable
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:2
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ConfigCollection

Specifies the ConfigurationCollection object to which the new collection element will be added. If a ConfigurationCollection is previously obtained and assigned to a variable, you cannot pass it to this cmdlet through the pipeline because the pipeline engine will try to enumerate it, passing ConfigurationElement objects instead. Try either passing the whole Get-IISConfigCollection cmdlet into the pipeline or use it as a parameter for correct results.

Parameter properties

Type:ConfigurationElementCollection
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:1
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:True
Value from remaining arguments:False

-Passthru

Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

ConfigurationElementCollection

Hashtable

UInt32

Outputs

Object