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 |
Related UI Task:"Explorer"
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 |
Related UI Task:"Explorer"
3. [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"
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]) |
Related UI Task:"Edit Permissions..."
5. [Application Pool] Get the list of application pools
Related UI Task:"Application Pools" treeview
6. [Application Pool] Create a new pool
|
New-Item iis:\apppools\demoAppPool |
Or, you can use other task-based cmdlet(s) instead:
NOTE: New-AppPool cannot use full path name such as “iis:\appPools\demoAppPool” like other user-friendly-named cmdlets
Related UI Task:"Add Application Pool..."
7. [Application Pool] Rename an Application Pool
| Rename-Item iis:\apppools\defaultapppool newAppPoolName |
Related UI Task:"Rename "
8. [Application Pool] Remove an Application Pool
|
Remove-Item iis:\apppools\defaultapppool |
Or, you can use other task-based cmdlet(s) instead:
| Remove-AppPool defaultapppool |
Related UI Task:"Remove "
9. [Application Pool] Stop/Start/Recycle Application Pool
| Start-WebItem IIS:\AppPools\DefaultAppPoolStop-WebItem IIS:\AppPools\DefaultAppPoolRestart-WebItem IIS:\AppPools\DefaultAppPool |
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"
10. [Application Pool] Get the current status of Application Pool
|
Get-WebItemState iis:\apppools\defaultapppool |
Or, you can use other task-based cmdlet(s) instead:
|
Get-AppPoolState defaultapppool |
Related UI Task:"Stop/Start/Recycle"
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)}} |
Related UI Task:"View Applications"
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//.PS IIS:\> $subsections | foreach { $_.attributes | select name,value } Name Value---- -----namequeueLength 1000autoStart Trueenable32BitAppOnWin64 FalsemanagedRuntimeVersion v2.0enableConfigurationOverride TruemanagedPipelineMode 0passAnonymousToken TrueidentityType 2userNamepasswordloadUserProfile FalsemanualGroupMembership FalseidleTimeout 00:20:00maxProcesses 1shutdownTimeLimit 00:01:30startupTimeLimit 00:01:30pingingEnabled TruepingInterval 00:00:30pingResponseTime 00:01:30disallowOverlappingRotation FalsedisallowRotationOnConfigChange FalselogEventOnRecycle 137memory 0privateMemory 0requests 0time 1.05:00:00value 11:59:00value 11:32:00loadBalancerCapabilities 1orphanWorkerProcess FalseorphanActionExeorphanActionParamsrapidFailProtection FalserapidFailProtectionInterval 00:05:00rapidFailProtectionMaxCrashes 5autoShutdownExeautoShutdownParamslimit 0action 0resetInterval 00:05:00smpAffinitized FalsesmpProcessorAffinityMask 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..."
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 programmaticallyPS 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 pathPS 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 cmdletPS IIS:\> add-webconfiguration /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart/schedule -value (New-TimeSpan -h 9 -m30) # Confirm the new value is addedPS IIS:\> get-webconfiguration /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart/schedule/add | select value value-----09:30:00 |
Related UI Task:"Set Application Pool Defaults..."
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 } |
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..."
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
Related UI Task:"Advanced Settings..."
16. [Application Pool] Get the list of application pools
Related UI Task:"Sites" treeview
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 |
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
18. [Sites] Set bindings
Case1: Create SSL Binding (127.0.0.1!443)
| $certObect = get-item cert:\LocalMachine\My\E48803C3A6DDC8F2BFE3D8B7B7D56BBA70270F92new-item IIS:\SslBindings\127.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:\Sites\Default 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:\sites\Default Web Site' -name bindings |
Related UI Task:"Bindings..."
19. [Sites] Rename an Web Site
|
Rename-Item "iis:\sites\default web site" newWebSiteName |
Related UI Task:"Rename "
20. [Sites] Remove an Web Site
|
Remove-Item "iis:\sites\default web site" |
Or, you can use other task-based cmdlet(s) instead:
|
Remove-WebSite " default web site" |
Related UI Task:"Remove "
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" |
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"
22. [Sites] Get the current status of Web Site
|
Get-WebItemState "IIS:\Sites\Default Web Site" |
Or, you can use other task-based cmdlet(s) instead:
|
Get-WebSiteState "Default Web Site" |
Related UI Task:"Stop/Start/Recycle"
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:\PS IIS:\> $subsections | foreach { $_.attributes | select name,value } Name Value---- -----nameid 0serverAutoStart TruemaxBandwidth 4294967295maxConnections 4294967295connectionTimeout 00:02:00logExtFileFlags 2215887customLogPluginClsidlogFormat 2directory %SystemDrive%\inetpub\logs\LogFilesperiod 1truncateSize 20971520localTimeRollover Falseenabled Trueenabled Falsedirectory %SystemDrive%\inetpub\logs\FailedReq...maxLogFiles 50maxLogFileSizeKB 512customActionsEnabled FalseallowUTF8 TrueserverAutoStart TrueunauthenticatedTimeout 30controlChannelTimeout 120dataChannelTimeout 30disableSocketPooling FalseserverListenBacklog 60minBytesPerSecond 240maxConnections 4294967295resetOnMaxConnections FalsemaxBandwidth 4294967295matchClientAddressForPort TruematchClientAddressForPasv TruemaxCommandLine 4096allowUnlisted TrueserverCertHashserverCertStoreName MYssl128 FalsecontrolChannelPolicy 1dataChannelPolicy 1clientCertificatePolicy 0useActiveDirectoryMapping FalsevalidationFlags 0revocationFreshnessTime 00:00:00revocationUrlRetrievalTimeout 00:01:00enabled FalseuserName IUSRpassworddefaultLogonDomain NT AUTHORITYlogonMethod 3enabled FalsedefaultLogonDomainlogonMethod 3enabled FalseimpersonationLevel 1exitMessagegreetingMessagebannerMessagemaxClientsMessagesuppressDefaultBanner FalseallowLocalDetailedErrors TrueexpandVariables FalsekeepPartialUploads FalseallowReplaceOnRename FalseallowReadUploadsInProgress FalseexternalIp4Addressmode 4adUserNameadPasswordadCacheRefresh 00:01:00showFlags 0virtualDirectoryTimeout 5logExtFileFlags 14716367directory D:\inetpub\logs\LogFilesperiod 1truncateSize 20971520localTimeRollover Falseenabled TrueselectiveLogging 7 |
Related UI Task:"Set Web Site Defaults..."
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 programmaticallyPS 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 pathPS IIS:\> set-webconfigurationproperty "/system.applicationHost/sites/siteDefaults[1]/limits[1]" -name connectionTimeout -value (New-TimeSpan -sec 130) |
Related UI Task:"Set Web Site Defaults..."
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 } |
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..."
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 |
Related UI Task:"Advanced Settings..."
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:\ |
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:\sites\default web site" |
Or, you can use other task-based cmdlet(s) instead:
|
Clear-FrebData -Site "default web site" |
Related UI Task:"Advanced Settings..."
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 SectionsPS IIS:\> $sections | select Name,OverrideModeDefault Name OverrideModeDefault---- -------------------httpProtocol AllowhttpErrors DenyhttpRedirect AllowglobalModules Denycgi DenyserverRuntime DenydirectoryBrowse AllowurlCompression AllowhttpLogging Denymodules DenyodbcLogging Denyvalidation AllowfastCgi Denyhandlers DenyhttpTracing DenystaticContent AllowisapiFilters DenydefaultDocument Allowasp DenyhttpCompression DenyserverSideInclude Denycaching 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
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 |
Related UI Task:UI Feature: UI has no related task for this.
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 optionPS 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-webconfigurationPS 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:\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" |
Related UI Task:UI Feature: "Feature Delegation" page
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 programmaticallyPS IIS:\> get-webconfiguration //*[@keepSessionIdSecure] | foreach {$_.itemxpath}/system.webServer/asp/session[1] # Set the property value with the section pathPS 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:\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 |
Related UI Task:UI Feature: "ASP" page
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
Related UI Task:UI Feature: "Authentication" page
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:\ |
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%\System32\inetsrv\cgi.dll -PSPath iis:\ |
Related UI Task:UI Feature: "Modules" page
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:\ |
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
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' |
Related UI Task:UI Feature:"Modules" page
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 DefaultAppPoolPS IIS:\AppPools\DefaultAppPool\WorkerProcesses> 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:\AppPools\DefaultAppPool\WorkerProcesses> get-webrequest -Process 3644 -AppPool defaultapppool requestId : fe00000080000466connectionId : fe00000060000463verb : GETurl : /long.aspxsiteId : 1 ### Or, you can use GetRequsts() method:PS IIS:\AppPools\DefaultAppPool\WorkerProcesses> (get-item 3644).getrequests($null) requestId : fe00000080000469connectionId : fe00000060000463verb : GETurl : /long.aspxsiteId : 1 |
Related UI Task:UI Feature: "Worker Processes" page