1. [File System] Open Explorer window for Default Web Site's home directory
$path = $(get-item 'iis:\sites\default web site').physicalPath $path = [system.environment]::ExpandEnvironmentVariables($path) explorer $path |
2. [File System] Open Explorer window for Default Web Site's home directory using "DirectoryName" property
$path = $(get-item 'iis:\sites\default web site\iisstart.htm').directoryName explorer $path |
3. [File System] Create File and set file content programmatically
$file = new-item demo.htm -type file set-content $file.FullName "Hey, dude!" |
4. [File System] Set "Deny" for administrator user account for 'iisstart.htm' file and grant access permission for NTAccount
$file = $(get-item "iis:\sites\Default Web Site\iisstart.htm ") $dacl = $file.GetAccessControl() $newRule = New-Object Security.AccessControl.FileSystemAccessRule Administrator, Modify, Deny $modified = $false $dacl.ModifyAccessRule("Add", $newRule, [ref]$modified) $file.SetAccessControl($dacl) $file.GetAccessControl().GetAccessRules($true, $true, [System.Security.Principal.NTAccount]) |
5. [Application Pool] Get the list of application pools
dir iis:\apppools |
6. [Application Pool] Create a new pool
New-Item iis:\apppools\demoAppPool |
New-AppPool demoAppPool |
NOTE: New-AppPool cannot use full path name such as “iis:\appPools\demoAppPool” like other user-friendly-named cmdlets
7. [Application Pool] Rename an Application Pool
Rename-Item iis:\apppools\defaultapppool newAppPoolName |
8. [Application Pool] Remove an Application Pool
Remove-Item iis:\apppools\defaultapppool |
Remove-AppPool defaultapppool |
9. [Application Pool] Stop/Start/Recycle Application Pool
Start-WebItem IIS:\AppPools\DefaultAppPool |
Start-AppPool DefaultAppPool Stop-AppPool DefaultAppPool Restart-AppPool DefaultAppPool |
10.[Application Pool] Get the current status of Application Pool
Get-WebItemState iis:\apppools\defaultapppool |
Get-AppPoolState defaultapppool |
11.[Application Pool] Get the list of application which is belonged to an Application Pool
function ConvertFrom-ItemXPath($itemXpath) { $result = new-object psobject $tempString = $itemXPath.substring($itemXPath.IndexOf("@name")) add-member -in $result noteproperty Site $tempString.Split("'")[1] $tempString = $itemXPath.substring($itemXPath.IndexOf("@path")) add-member -in $result noteproperty Application $tempString.Split("'")[1] return $result } $applications = get-webconfiguration //application[@applicationPool] $applications | select itemXpath, applicationpool | foreach {if ($_.applicationPool -eq "DefaultAppPool") {ConvertFrom-ItemXPath ($_.itemXpath)}} |
12.[Application Pool] Get Application Pool Default Settings
$subsections = get-webconfiguration //applicationPoolDefaults//. -PSPATH iis:\ $subsections | foreach { $_.attributes | select name,value } |
PS IIS:\> $subsections = get-webconfiguration //applicationPoolDefaults//. |
logEventOnRecyle property value shows number value, which is not human-readable. You can get the text enum value by querying the specific property instead such as shown in the following:
get-webconfiguration //applicationPoolDefaults/recycling/@logEventOnRecycle |
PS IIS:\> get-webconfiguration //applicationPoolDefaults/recycling/@logEventOnRe |
13.[Application Pool] Set Application Pool Default Settings
Case1: Setting queueLength, which is “property” type
set-webconfigurationproperty /system.applicationHost/applicationPools/applicationPoolDefaults[1]/failure[1] -name rapidFailProtectionMaxCrashes -value 10 |
# You could get the section path of the target property programmatically |
Case2: Setting schedule, which is “element” type (shown as “Specific Times” in UI)
add-webconfiguration /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart/schedule -value (New-TimeSpan -h 9 -m30) |
# Add new ‘Add’ element with a new-timespan value and add-webconfiguration cmdlet |
14.[Application Pool] Get configuration settings for a specific application pool
$configSection = "/system.applicationHost/applicationPools/add[@name='DefaultAppPool']//." $subsections = get-webconfiguration $configSection -PSPath iis:\ $subsections | foreach { $_.attributes | select name,value } |
$subsections = get-webconfiguration '//*[@name="DefaultAppPool"]//.' -PSPath iis:\ $subsections | foreach { $_.attributes | select name,value } |
15.[Application Pool] Set configuration settings for a specific application pool
Case1: Setting logEventOnRecycle, which is “enum property” type
$configSection = "/system.applicationHost/applicationPools/add[@name='DefaultAppPool']/recycling" set-webconfigurationproperty $configSection -name logEventOnRecycle -value 1 -PSPath iis:\ |
NOTE: The value could be set with "Time" in the next version instead of 1 for the above example
16.[Application Pool] Get the list of application pools
Dir iis:\sites |
17.[Sites] Create a new Web Site
Case1: Create web site with single binding
$binding = @{protocol="http";bindingInformation="*:80:hostname"} new-item "iis:\sites\demoSite" -type site –physicalPath c:\demoSite -bindings $binding |
Case2: Create web site with multiple binding and specific id
$binding = (@{protocol="http";bindingInformation="*:80:hostname"},@{protocol="http";bindingInformation="*:80:hostname2"}) new-item "iis:\sites\demoSite" -type site -physicalPath c:\demoSite -bindings $binding -id 555 |
New-WebSite -Name DemoSite -Port 80 -HostHeader hostname –PhysicalPath c:\demoSite –ID 555 New-WebBinding -Site DemoSite -Port 80 -IPAddress * -HostHeader hostname2 |
18.[Sites] Set bindings
Case1: Create SSL Binding (127.0.0.1!443)
$certObect = get-itemcert:\LocalMachine\My\E48803C3A6DDC8F2BFE3D8B7B7D56BBA70270F92 |
PS IIS:\> dir cert:\LocalMachine\My |
Case2: Set 'Bindings' property with multiple binding information including the SSL binding which was created above.
$newBinding = (@{protocol="http";bindingInformation="127.0.0.1:80:normalSite"},@{protocol="https";bindingInformation="127.0.0.1:443:securedSite"}) Set-itemproperty "IIS:\Sites\Default Web Site" -name bindings -value $newBinding |
New-WebBinding -Site "Default Web Site" -Port 443 -IPAddress 127.0.0.1 -HostHeader securedSite |
NOTE: you can also use set-webconfiguration, set-webconfiguration or add-webconfigurationProperty.
Set-Webconfiguration '/system.applicationHost/sites/site[@name ="Default Web Site"]/bindings' -value $newBinding -PSPath iis:\ Set-WebconfigurationProperty '/system.applicationHost/sites/site[@name ="Default Web Site"]' -name bindings.collection -value $newBinding -at 0 -PSPath iis:\ Add-WebconfigurationProperty '/system.applicationHost/sites/site[@name ="Default Web Site"]' -name bindings.collection -value @{protocol="https";bindingInformation="127.0.0.1:443:securedSite"} -at 0 -PSPath iis:\ |
Case3: Change a certain value of existing 'Bindings' property using other task-based cmdlet.
Set-WebBinding -Site "Default Web Site" -Port 443 -IPAddress 127.0.0.1 -HostHeader securedSite -name Port -value 444 |
Case4: Removing binding information using other task-based cmdlet.
Remove-WebBinding -Site "Default Web Site" -Port 443 -IPAddress 127.0.0.1 -HostHeader securedSite |
Or, you can use Remove-WebConfigurationProperty
Remove-WebconfigurationProperty '/system.applicationHost/sites/site[@name="Default Web Site"]' -name Bindings.collection -at @{protocol="https";bindingInformation="127.0.0.1:443:securedSite"} -PSPath iis:\ |
Case5: Clear all the binding information of a certain web site
Clear-Webconfiguration '/system.applicationHost/sites/site[@name="Default Web Site"]/bindings' -PSPath iis:\ |
NOTE: you can also use clear-itemproperty instead:
Clear-ItemProperty 'iis:\sites\Default Web Site' -name bindings |
19.[Sites] Rename an Web Site
Rename-Item "iis:\sites\default web site" newWebSiteName |
20.[Sites] Remove an Web Site
Remove-Item "iis:\sites\default web site" |
Remove-WebSite " default web site" |
21.[Sites] Stop/Start/Restart Web Site
Start-WebItem "IIS:\Sites\Default Web Site" Stop-WebItem "IIS:\Sites\Default Web Site" Restart-WebItem "IIS:\Sites\Default Web Site" |
Start-WebSite "Default Web Site" Stop-WebSite "Default Web Site" Restart-WebSite "Default Web Site" |
22.[Sites] Get the current status of Web Site
Get-WebItemState "IIS:\Sites\Default Web Site" |
Get-WebSiteState "Default Web Site" |
23.[Sites] Get Web Site Defaults Settings
$subsections = get-webconfiguration //siteDefaults//. -PSPATH iis:\ $subsections | foreach { $_.attributes | select name,value } |
PS IIS:\> $subsections = get-webconfiguration //siteDefaults//. -PSPATH iis:\ |
24.[Sites] Set Web Site Default Settings
Case1: Setting connectionTimeout
set-webconfigurationproperty "/system.applicationHost/sites/siteDefaults[1]/limits[1]" -name connectionTimeout -value (New-TimeSpan -sec 130) |
# You could get the section path of the target property programmatically |
25.[Sites] Get configuration settings for a specific web site
$configSection = "/system.applicationHost/sites/site[@name='Default Web Site']//." $subsections = get-webconfiguration $configSection -PSPath iis:\ $subsections | foreach { $_.attributes | select name,value } |
$subsections = get-webconfiguration '//*[@name="Default Web Site"]//.' -PSPath iis:\ $subsections | foreach { $_.attributes | select name,value } |
26.[Sites] Set configuration settings for a specific web site
Case1: Setting maxLogFiles
$configSection = "/system.applicationHost/sites/site[@name='Default Web Site' and @id='1']/traceFailedRequestsLogging" set-webconfigurationproperty $configSection -name maxLogFiles -value 60 -PSPath iis:\ |
If you are trying to change basic properties, you could also use set-itemProperty as shown in the following:
Case2: 'Application Pool' property
Set-Itemproperty IIS:\Sites\DemoSite -name applicationPool -value demo AppPool |
Case3: 'Physical Path' property
set-itemproperty IIS:\Sites\DemoSite -name physicalPath -value c:\demoSite2 |
Case4: 'username' property
set-itemproperty IIS:\Sites\DemoSite -name userName -value newUserId |
Case5: 'password' property
set-itemproperty IIS:\Sites\DemoSite -name password -value newPassword |
27.[Sites] Set Failed Request Tracing for a specific web site
Case1: Enable Freb for a specific web site with setting maxLogFiles and directory
$configSection = "/system.applicationHost/sites/site[@name='Default Web Site' and @id='1']/traceFailedRequestsLogging" set-webconfigurationproperty $configSection -name maxLogFiles -value 60 -PSPath iis:\ set-webconfigurationproperty $configSection -name directory -value c:\MyFailedReqLogFiles -PSPath iis:\ |
Enable-Freb -Site "default web site" -Directory "c:\MyFailedReqLogFiles" -MaxLogFileSize 555 |
Case2: Disable Freb for a specific web site
$configSection = "/system.applicationHost/sites/site[@name='Default Web Site' and @id='1']/traceFailedRequestsLogging" set-webconfigurationproperty $configSection -name enabled -value false -PSPath iis:\ |
Disable-Freb -Site "default web site" |
Case3: Clear Freb data for a specific web site
If you use Enable-Freb, it creates following default setting of Freb settings for the specified sites. We can clear them by this way.
<?xml version="1.0" encoding="UTF-8"?> |
Clear-WebConfiguration /system.webServer/tracing/traceFailedRequests -PSPath "iis:\sites\default web site" |
Clear-FrebData -Site "default web site" |
28.[Management] Read default feature Delegation settings
Case1: Dump all sectionGroups
get-webconfigurationproperty / -name sectiongroups |
Case2: Dump specific sectionGroup such as "system.applicationHost"
get-webconfigurationproperty / -name sectiongroups["system.applicationHost"] |
Case3: Dump all sections under "/" group
get-webconfigurationproperty / -name Sections |
NOTE: You will see empty value because IIS configuration system does not have section under "root" level by default
Case4: Dump all sections under specific sectionGroup such as "system.webServer"
$sections = get-webconfigurationproperty /system.webserver -name Sections $sections | select Name,OverrideModeDefault |
PS IIS:\> $sections = get-webconfigurationproperty /system.webserver -name Sections |
NOTE: Now you can see the default override mode for "ASP" config section is deny, which means we can configure ASP related properties only for 'server' level
29.[Management] Add/Remove customized IIS config section
Case1: Add "myGroup" sectiongroup under root
add-webconfigurationproperty / -name SectionGroups -value myGroup |
Case2: Add "mySection" section under the myGroup sectiongroup which was created above
add-webconfigurationproperty /myGroup -name Sections -value mySection |
Case3: Set OverrideModeDefault for the newly created section, "mySection"
set-webconfigurationproperty /myGroup -name Sections["mySection"].OverrideModeDefault -value Deny |
Case4: Set AllowDefinition for the newly created section, "mySection"
set-webconfigurationproperty /myGroup -name Sections["mySection"].AllowDefinition -value AppHostOnly |
Case5: Set AllowLocation for the newly created section, "mySection"
set-webconfigurationproperty /myGroup -name Sections["mySection"].AllowLocation -value false |
Case6: Remove the "mySection" section which were created above
remove-webconfigurationproperty /myGroup -name Sections -at mySection |
Case7: Remove the "myGroup" sectiongroup which were created above
remove-webconfigurationproperty / -name SectionGroups -at myGroup |
30.[Management] Configure Feature Delegation related settings
NOTE: Before changing delegation setting of a config section, you would need to remove previously configured properties and elements of the section and re-configure them again after the delegation setting is updated.
This is an example of how to remove ASP sections using clear-webconfiguration cmdlet:
clear-webconfiguration /system.webServer/asp -pspath MACHINE/WEBROOT/A PPHOST/testSite clear-webconfiguration /system.webServer/asp -pspath MACHINE/WEBROOT/A PPHOST |
# Get the list of previously configured items using -recurse option |
Case1: Read the current Delegation setting of ASP feature for 'server' level
get-webconfiguration //asp iis:\ | select OverrideMode |
PS IIS:\> get-webconfiguration //asp iis:\ | select OverrideMode |
NOTE: The value "inherit" means it uses the default override mode and it is actually "Deny" in the default IIS configuration
Case2: Set "Read-Write" for ASP feature for 'server' level
set-webconfiguration //asp -metadata overrideMode -value Allow -PSPath iis:\ |
Case3: Set "Not Delegated" for ASP feature for 'server' level
NOTE: "Not Delegated" task is only applicable to IIS UI world. Please use "Read Only" which is explained below.
Case4: Set "Read Only" for ASP feature for 'server' level
set-webconfiguration //asp -metadata overrideMode -value Deny -PSPath iis:\ |
Case5: Set "Reset to Inherited" for ASP feature for 'server' level
set-webconfiguration //asp -metadata overrideMode -value Inherit -PSPath iis:\ |
Case6: Change Delegation settings for 'site' level
set-webconfiguration //asp -metadata overrideMode -value Inherit -PSPath "iis:\sites\default web site" |
Case7: Change Delegation settings for 'site' level using location
set-webconfiguration //asp -metadata overrideMode -value Inherit -PSPath "iis:\sites" -Location "default web site" |
31.[IIS] Configure Clasic ASP properties
Case1: Read all ASP settings from 'server' level
$subsections = get-webconfiguration //asp//. -PSPATH iis:\ $subsections | foreach { $_.attributes | select name,value } |
Case2: Read all ASP settings from 'web site' level such as "Default Web Site"
$subsections = get-webconfiguration //asp//. -PSPATH "iis:\sites\default web site" $subsections | foreach { $_.attributes | select name,value } |
Case3: Read all ASP settings from 'web application' level such as "DemoApplication "
$subsections = get-webconfiguration //asp//. -PSPATH "iis:\sites\default web site\demoapplication" $subsections | foreach { $_.attributes | select name,value } |
Case4: Read all ASP settings from 'file' level which is under an Web Site
$subsections = get-webconfiguration //asp//. -PSPATH "iis:\sites\default web site" -location iisstart.htm $subsections | foreach { $_.attributes | select name,value } |
Case5: Write an ASP setting, keepSessionIdSecure, for 'server' level
set-webconfigurationproperty "/system.webServer/asp/session[1]" -name keepSessionIdSecure -value true -PSPath iis:\ |
# You could get the section path of the target property programmatically |
Case6: Write an ASP setting, keepSessionIdSecure, for 'site' level
set-webconfigurationproperty "/system.webServer/asp/session[1]" -namekeepSessionIdSecure -value true -PSPath "iis:\sites\default web site" |
Case5: Write an ASP setting, keepSessionIdSecure, for 'file' level which is under an Web Site
set-webconfigurationproperty "/system.webServer/asp/session[1]" -name keepSessionIdSecure -value true -PSPath "iis:\sites\default web site" -location iisstart.htm |
32.[IIS] Configure Authentication properties
Case1: List all of authentications and from 'server' level
get-webconfiguration /system.webServer/security/authentication/*[@enabled] -PSPath iis:\ | select ItemXPath,enabled |
Case2: List all of authentications and from 'site' level
get-webconfiguration /system.webServer/security/authentication/*[@enabled] -PSPath "iis:\sites\default web site"| select ItemXPath,enabled |
NOTE: You can also get from other levels adjusting the value -PSPath and -Location parameter values
Case3: Get all of Anonymous authentication properties from 'server' level
$attributes = (Get-WebConfiguration /system.webServer/security/authentication/anonymousAuthentication -PSPath iis:\).attributes $attributes | select name,value |
NOTE: You can also get from other levels adjusting the value -PSPath and -Location parameter values
Case4: Change userName property for Anonymous authentication properties from 'server' level
Set-WebConfigurationproperty system.webServer/security/authentication/anonymousAuthentication -name userName -value "" -PSPath iis:\ |
NOTE: You can also set for other levels adjusting the value -PSPath and -Location parameter values
33.[IIS] Configure Module elements and properties which are configured in globalModules section
Case1: List all native modules
(Get-WebConfiguration //globalmodules).collection -PSPath iis:\ |
Case2: Add a new native modue at the bottom index of the existing modules
Add-WebConfigurationProperty //globalmodules -name collection -value @{name='testmodule';image='c:\test.dll'} -PSPath iis:\ |
New-WebModule -Name testmodule -Image c:\test.dll -Precondition "integratedMode" |
Case3: Add a new native modue at the top index of the existing modules
Add-WebConfigurationProperty //globalmodules -name collection -value @{name='testmodule';image='c:\test.dll'} -at 0 -PSPath iis:\ |
Case4: Remove a native modue with a number index value
Remove-WebConfigurationProperty //globalmodules -name collection -at 0 -PSPath iis:\ |
Case5: Remove a native modue with a hashtable index value
Remove-WebConfigurationProperty //globalmodules -name collection -at @{name='testmodule';image='c:\test.dll'} -PSPath iis:\ |
Remove-WebModule -Name testmodule |
Case6: Get the attributes for a specific module
$modules = (get-webconfiguration //globalmodules -PSPath iis:\).collection $modules | foreach {if ($_.name -eq "cgiModule") { $_.attributes | select name, value}} |
Case7: Change an attribute value for a specific module
Get-Webconfigurationproperty '//globalmodules/add[@name="CgiModule"]' -name image -PSPath iis:\ Set-Webconfigurationproperty '//globalmodules/add[@name="CgiModule"]' -name image -value %windir%\System32\inetsrv\cgi.dll -PSPath iis:\ |
34.[IIS] Configure Module elements and properties
Case1: Enable/Disable a native modue
Add-WebConfigurationProperty //modules -name collection -value @{name='testmodule';lockItem='true'} -at 0 -PSPath iis:\ |
Enable-WebModule -Name testModule |
Case2: Add a new managedModule
Add-WebConfigurationProperty //modules -name collection -value @{name='newManagedModule';type='Microsoft.IIS.DemoModule'} -PSPath iis:\ |
New-Managedwebmodule -name newManagedModule -Type Microsoft.IIS.DemoModule |
Case3: Disable module by removing the module element from the <modules> section
Remove-WebConfigurationProperty //modules -name collection -at @{name='testmodule';lockItem='true'} -PSPath iis:\ |
Disable-WebModule -Name testModule |
Case4: List all of enabled modules from 'server' level
(get-webconfiguration //modules -PSPath iis:\).collection -PSPath iis:\ |
Get-WebModule -PSPath iis:\ -enabled |
Case5: Get the attributes for a specific module
$modules = (get-webconfiguration //modules -PSPath iis:\).collection $modules | foreach {if ($_.name -eq "cgiModule") { $_.attributes | select name, value}} |
Case6: Change an attribute value for a specific module
Get-Webconfigurationproperty '//modules/add[@name="CgiModule"]' -name lockItem -PSPath iis:\ Set-Webconfigurationproperty '//modules/add[@name="CgiModule"]' -name lockItem -value true -PSPath iis:\ |
35.[IIS] Change order Module elements and Revert To Inherit for a site level
Case1: Move testmodule to bottom index
# remove the target item and then re-create the item Remove-WebConfigurationProperty //modules -name collection -at @{name='testmodule';lockItem='true'} -PSPath iis:\ Add-WebConfigurationProperty //modules -name collection -value @{name='testmodule';lockItem='true'} -PSPath iis:\ |
Case2: Revert To Inherit for 'site' level
Clear-WebConfiguration //modules -name -PSPath 'iis:\sites\default web site' |
36.[IIS] Get the list of worker processes and requests which is running on an Application Pool
get-webrequest -Process 3644 -AppPool defaultapppool |
### Get the process information of DefaultAppPool |