IIS Powershell User guide - Comparing representative IIS UI tasks
- [File System] Open Explorer window for Default Web Site's home directory
$path=$(get-item 'iis:sitesdefault web site').physicalPath $path=[system.environment]::ExpandEnvironmentVariables($path) explorer $path
Related UI Task:"Explorer"
- [File System] Open Explorer window for Default Web Site's home directory using "DirectoryName" property
$path=$(get-item 'iis:sitesdefault web siteiisstart.htm').directoryName explorer $path
Related UI Task:"Explorer"
- [File System] Create File and set file content programmatically
$file=new-item demo.htm -type file set-content $file.FullName "Hey, dude!"
Related UI Task:"Explorer"
- [File System] Set "Deny" for administrator user account for 'iisstart.htm' file and grant access permission for NTAccount
$file=$(get-item "iis:sitesDefault Web Siteiisstart.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])
Related UI Task:"Edit Permissions..."
- [Application Pool] Get the list of application pools
dir iis:apppools
Related UI Task:"Application Pools" treeview
- [Application Pool] Create a new pool
New-Item iis:apppoolsdemoAppPool
Or, you can use other task-based cmdlet(s) instead:
New-AppPool demoAppPool
NOTE: New-AppPool cannot use full path name such as “iis:appPoolsdemoAppPool” like other user-friendly-named cmdlets
Related UI Task:"Add Application Pool..."
- [Application Pool] Rename an Application Pool
Rename-Item iis:apppoolsdefaultapppool newAppPoolName
Related UI Task:"Rename "
- [Application Pool] Remove an Application Pool
Remove-Item iis:apppoolsdefaultapppool
Or, you can use other task-based cmdlet(s) instead:
Remove-AppPool defaultapppool
Related UI Task:"Remove "
- [Application Pool] Stop/Start/Recycle Application Pool
Start-WebItem IIS:AppPoolsDefaultAppPoolStop-WebItem IIS:AppPoolsDefaultAppPoolRestart-WebItem IIS:AppPoolsDefaultAppPool
Or, you can use other task-based cmdlet(s) instead:
Start-AppPool DefaultAppPool Stop-AppPool DefaultAppPool Restart-AppPool DefaultAppPool
Related UI Task:"Stop/Start/Recycle"
- [Application Pool] Get the current status of Application Pool
Get-WebItemState iis:apppoolsdefaultapppool
Or, you can use other task-based cmdlet(s) instead:
Get-AppPoolState defaultapppool
Related UI Task:"Stop/Start/Recycle"
- [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)}}
Related UI Task:"View Applications"
- [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//. PS IIS:\> $subsections | foreach { $_.attributes | select name,value } Name Value ---- ----- namequeueLength 1000 autoStart True enable32BitAppOnWin64 False managedRuntimeVersion v2.0 enableConfigurationOverride True managedPipelineMode 0 passAnonymousToken True identityType 2 userName password loadUserProfile False manualGroupMembership False idleTimeout 00:20:00 maxProcesses 1 shutdownTimeLimit 00:01:30 startupTimeLimit 00:01:30 pingingEnabled True pingInterval 00:00:30 pingResponseTime 00:01:30 disallowOverlappingRotation False disallowRotationOnConfigChange False logEventOnRecycle 137 memory 0 privateMemory 0 requests 0 time 1.05:00:00 value 11:59:00 value 11:32:00 loadBalancerCapabilities 1 orphanWorkerProcess False orphanActionExe orphanActionParams rapidFailProtection False rapidFailProtectionInterval 00:05:00 rapidFailProtectionMaxCrashes 5 autoShutdownExe autoShutdownParamslimit 0 action 0 resetInterval 00:05:00 smpAffinitized False smpProcessorAffinityMask 4294967295
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/@logEventOnRecycleTime,Memory
Related UI Task:"Set Application Pool Defaults..."
- [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 PS IIS:\> get-webconfiguration //*[@rapidFailProtectionMaxCrashes] | foreach {$_.itemXPath}/system.applicationHost/applicationPools/applicationPoolDefaults[1]/failure[1]/system.applicationHost/applicationPools/add[@name='DefaultAppPool']/failure[1]/system.applicationHost/applicationPools/add[@name='Classic .NET AppPool']/failure[1] # Set the property value with the section path PS IIS:\> set-webconfigurationproperty /system.applicationHost/applicationPools/applicationPoolDefaults[1]/failure[1] -name rapidFailProtectionMaxCrashes -value 10 NOTE: “applicationPoolDefaults[1]/failure[1]” is equivalent to “applicationPoolDefaults/failure”.
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 PS IIS:\> add-webconfiguration /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart/schedule -value (New-TimeSpan -h 9 -m30) # Confirm the new value is added PS IIS:\> get-webconfiguration /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart/schedule/add | select value value-----09:30:00
Related UI Task:"Set Application Pool Defaults..."
- [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 }
Or, you can use “*” instead of the full config section path:
$subsections=get-webconfiguration '//*[@name="DefaultAppPool"]//.' -PSPath iis: $subsections | foreach { $_.attributes | select name,value }
Related UI Task:"Advanced Settings..."
- [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
Related UI Task:"Advanced Settings..."
- [Application Pool] Get the list of application pools
Dir iis:sites
Related UI Task:"Sites" treeview
- [Sites] Create a new Web Site
Case1: Create web site with single binding
$binding=@{protocol="http";bindingInformation="*:80:hostname"} new-item "iis:sitesdemoSite" -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:sitesdemoSite" -type site -physicalPath c:demoSite -bindings $binding -id 555
Or, you can use other task-based cmdlet(s) instead:
New-WebSite -Name DemoSite -Port 80 -HostHeader hostname –PhysicalPath c:demoSite –ID 555 New-WebBinding -Site DemoSite -Port 80 -IPAddress * -HostHeader hostname2
Related UI Task:"Add Web Site..." wizard
- [Sites] Set bindings
Case1: Create SSL Binding (127.0.0.1!443)
$certObect=get-item cert:LocalMachineMyE48803C3A6DDC8F2BFE3D8B7B7D56BBA70270F92new-item IIS:SslBindings127.0.0.1!443 -value $certObect
PS IIS:\> dir cert:\LocalMachine\My Directory: Microsoft.PowerShell.Security\Certificate::LocalMachine\My Thumbprint Subject ---------- ------- E48803C3A6DDC8F2BFE3D8B7B7D56BBA70270F92 CN=WMSvc-JHKIM-WTT3 PS IIS:\> $certObect = get-item cert:\LocalMachine\My\E48803C3A6DDC8F2BFE3D8B7B7D56BBA70270F92 PS IIS:\> new-item IIS:\SslBindings\127.0.0.1!443 -value $certObect IP Address Port Store Sites ---------- ---- ----- ----- 127.0.0.1 443 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:SitesDefault Web Site" -name bindings -value $newBinding
Or, you can use other task-based cmdlet(s) instead:
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:sitesDefault Web Site' -name bindings
Related UI Task:"Bindings..."
- [Sites] Rename an Web Site
Rename-Item "iis:sitesdefault web site" newWebSiteName
Related UI Task:"Rename"
- [Sites] Remove an Web Site
Remove-Item "iis:sitesdefault web site"
Or, you can use other task-based cmdlet(s) instead:
Remove-WebSite " default web site"
Related UI Task:"Remove "
- [Sites] Stop/Start/Restart Web Site
Start-WebItem "IIS:SitesDefault Web Site" Stop-WebItem "IIS:SitesDefault Web Site" Restart-WebItem "IIS:SitesDefault Web Site"
Or, you can use other task-based cmdlet(s) instead:
Start-WebSite "Default Web Site" Stop-WebSite "Default Web Site" Restart-WebSite "Default Web Site"
Related UI Task:"Stop/Start/Restart"
- [Sites] Get the current status of Web Site
Get-WebItemState "IIS:SitesDefault Web Site"
Or, you can use other task-based cmdlet(s) instead:
Get-WebSiteState "Default Web Site"
Related UI Task:"Stop/Start/Recycle"
- [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:\ PS IIS:\> $subsections | foreach { $_.attributes | select name,value } Name Value ---- ----- nameid 0 serverAutoStart True maxBandwidth 4294967295 maxConnections 4294967295 connectionTimeout 00:02:00 logExtFileFlags 2215887 customLogPluginClsidlogFormat 2 directory %SystemDrive%\inetpub\logs\LogFiles period 1 truncateSize 20971520 localTimeRollover False enabled True enabled False directory %SystemDrive%\inetpub\logs\FailedReq... maxLogFiles 50 maxLogFileSizeKB 512 customActionsEnabled False allowUTF8 True serverAutoStart True unauthenticatedTimeout 30 controlChannelTimeout 120 dataChannelTimeout 30 disableSocketPooling False serverListenBacklog 60 minBytesPerSecond 240 maxConnections 4294967295 resetOnMaxConnections False maxBandwidth 4294967295 matchClientAddressForPort True matchClientAddressForPasv True maxCommandLine 4096 allowUnlisted True serverCertHashserverCertStoreName MY ssl128 False controlChannelPolicy 1 dataChannelPolicy 1 clientCertificatePolicy 0 useActiveDirectoryMapping False validationFlags 0 revocationFreshnessTime 00:00:00 revocationUrlRetrievalTimeout 00:01:00 enabled False userName IUSRpassword defaultLogonDomain NT AUTHORITY logonMethod 3 enabled False defaultLogonDomain logonMethod 3 enabled False impersonationLevel 1 exitMessage greetingMessage bannerMessage maxClientsMessage suppressDefaultBanner False allowLocalDetailedErrors True expandVariables False keepPartialUploads False allowReplaceOnRename False allowReadUploadsInProgress False externalIp4Addressmode 4 adUserName adPasswordadCacheRefresh 00:01:00 showFlags 0 virtualDirectoryTimeout 5 logExtFileFlags 14716367 directory D:\inetpub\logs\LogFiles period 1 truncateSize 20971520 localTimeRollover False enabled True selectiveLogging 7
Related UI Task:"Set Web Site Defaults..."
- [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 PS IIS:\> get-webconfiguration //*[@connectionTimeout] | foreach {$_.itemxpath}/system.applicationHost/webLimits/system.applicationHost/sites/siteDefaults[1]/limits[1]/system.applicationHost/sites/site[@name='Default Web Site' and @id='1']/limits[1] # Set the property value with the section path PS IIS:\> set-webconfigurationproperty "/system.applicationHost/sites/siteDefaults[1]/limits[1]" -name connectionTimeout -value (New-TimeSpan -sec 130)
Related UI Task:"Set Web Site Defaults..."
- [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 }
Or, you can use “*” instead of the full config section path:
$subsections=get-webconfiguration '//*[@name="Default Web Site"]//.' -PSPath iis: $subsections | foreach { $_.attributes | select name,value }
Related UI Task:"Advanced Settings..."
- [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:SitesDemoSite -name applicationPool -value demo AppPool
Case3: 'Physical Path' property
set-itemproperty IIS:SitesDemoSite -name physicalPath -value c:demoSite2
Case4: 'username' property
set-itemproperty IIS:SitesDemoSite -name userName -value newUserId
Case5: 'password' property
set-itemproperty IIS:SitesDemoSite -name password -value newPassword
Related UI Task:"Advanced Settings..."
- [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:
Or, you can use other task-based cmdlet(s) instead:
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:
Or, you can use other task-based cmdlet(s) instead:
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"?><configuration> <system.webServer> <tracing> <traceFailedRequests> <add path="*"> <traceAreas> <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module" verbosity="Verbose" /> <add provider="ASP" verbosity="Verbose" /> <add provider="ISAPI Extension" verbosity="Verbose" /> <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" /> </traceAreas> <failureDefinitions timeTaken="00:00:30" statusCodes="500" verbosity="Warning" /> </add> </traceFailedRequests> </tracing> </system.webServer></configuration>
Clear-WebConfiguration /system.webServer/tracing/traceFailedRequests -PSPath "iis:sitesdefault web site"
Or, you can use other task-based cmdlet(s) instead:
Clear-FrebData -Site "default web site"
Related UI Task:"Advanced Settings..."
- [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 PS IIS:\> $sections | select Name,OverrideModeDefault Name OverrideModeDefault ---- ------------------- httpProtocol Allow httpErrors Deny httpRedirect Allow globalModules Deny cgi Deny serverRuntime Deny directoryBrowse Allow urlCompression Allow httpLogging Deny modules Deny odbcLogging Deny validation Allow fastCgi Deny handlers Deny httpTracing Deny staticContent Allow isapiFilters Deny defaultDocument Allow asp Deny httpCompression Deny serverSideInclude Deny caching Allow
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
Related UI Task:UI Feature: "Feature Delegation" page
- [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
Related UI Task:UI Feature: UI has no related task for this.
- [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 PS IIS:\> get-webconfiguration //asp -Recurse SectionPath PSPath ----------- ------ /system.webServer/asp MACHINE/WEBROOT/APPHOST/system.webServer/asp MACHINE/WEBROOT/APPHOST/testSite # Clear those items using clear-webconfiguration PS IIS:\> clear-webconfiguration /system.webServer/asp -pspath MACHINE/WEBROOT/APPHOST/testSitePS IIS:\> clear-webconfiguration /system.webServer/asp -pspath MACHINE/WEBROOT/APPHOST
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 OverrideMode------------Inherit
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:sitesdefault 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"
Related UI Task:UI Feature: "Feature Delegation" page
- [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:sitesdefault 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:sitesdefault web sitedemoapplication" $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:sitesdefault 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 PS IIS:> get-webconfiguration //*[@keepSessionIdSecure] | foreach {$_.itemxpath}/system.webServer/asp/session[1] # Set the property value with the section path PS IIS:> set-webconfigurationproperty "/system.webServer/asp/session[1]" -name keepSessionIdSecure -value true -PSPath iis:
Case6: Write an ASP setting, keepSessionIdSecure, for 'site' level
set-webconfigurationproperty "/system.webServer/asp/session[1]" -name keepSessionIdSecure -value true -PSPath "iis:sitesdefault 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:sitesdefault web site" -location iisstart.htm
Related UI Task:UI Feature: "ASP" page
- [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:sitesdefault 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
Related UI Task:UI Feature: "Authentication" page
- [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:
Or, you can use other task-based cmdlet(s) instead:
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:
Or, you can use other task-based cmdlet(s) instead:
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%System32inetsrvcgi.dll -PSPath iis:
Related UI Task:UI Feature: "Modules" page
- [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:
Or, you can use other task-based cmdlet(s) instead:
Enable-WebModule -Name testModule
Case2: Add a new managedModule
Add-WebConfigurationProperty //modules -name collection -value @{name='newManagedModule';type='Microsoft.IIS.DemoModule'} -PSPath iis:
Or, you can use other task-based cmdlet(s) instead:
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:
Or, you can use other task-based cmdlet(s) instead:
Disable-WebModule -Name testModule
Case4: List all of enabled modules from 'server' level
(get-webconfiguration //modules -PSPath iis:).collection -PSPath iis:
Or, you can use other task-based cmdlet(s) instead:
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:
Related UI Task:UI Feature:"Modules" page
- [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:sitesdefault web site'
Related UI Task:UI Feature:"Modules" page
- [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 PS IIS:AppPoolsDefaultAppPoolWorkerProcesses> dir Process State Handles Start TimeId -------- ----- ------- ---------- 3644 Running 310 7/24/2008 4:23:22 PM ### Call Get-WebRequest to get the list of requests using the process informationPS IIS:AppPoolsDefaultAppPoolWorkerProcesses> get-webrequest -Process 3644 -AppPool defaultapppool requestId : fe00000080000466connectionId : fe00000060000463verb : GETurl : /long.aspxsiteId : 1 ### Or, you can use GetRequsts() method:PS IIS:AppPoolsDefaultAppPoolWorkerProcesses> (get-item 3644).getrequests($null) requestId : fe00000080000469connectionId : fe00000060000463verb : GETurl : /long.aspxsiteId : 1
Related UI Task:UI Feature: "Worker Processes" page