Set-WebConfigurationProperty to change parameter is slow

530 Views Asked by At

I have a WebSite running with WebDav in Windows server 2012, it contains 10,000 web applications, it is working properly, recently I would like to migrate it to Windows server 2019, I use poweshell scripts to bulk create 10,000 web applications and change the parameter of Authentication and WebDAV Authoring Rules Value, however, it takes time to run, for example, it takes 4 seconds for one account at the beginning, after generated 5000 accounts, it takes 7 seconds for one account, finally, it takes around 15 seconds for last account, it run slower and slower, after 10,000 applications created, the WebSite even can't start, the W3SVC service keep stopping. Can I simplify the script to let it run faster? is there any limitation on IIS 10 in Windows Server 2019? please note that the web server is running in VM environment and higher CPU and RAM resources than existing Windows 2012, besides, I also try to use appcmd.exe or vb script to bulk create the web applications, but it also takes time to run.

Import-Csv Account.csv | ForEach-Object {

New-WebApplication -Site " WebSite" -Name "$($_.User)" -PhysicalPath "$($_.Path)"
Set-WebConfigurationProperty -Filter '/system.webServer/security/authentication/anonymousAuthentication' -Location " WebSite/$($_.User)" -Name enabled -Value False
Set-WebConfigurationProperty -Filter '/system.webServer/security/authentication/basicAuthentication' -Location " WebSite/$($_.User)" -Name enabled -Value True
Set-WebConfigurationProperty -Filter '/system.webServer/security/authentication/basicAuthentication' -Location " WebSite/$($_.User)" -Name defaultlogondomain -Value 'company.com'
Set-WebConfigurationProperty -Filter '/system.webServer/security/authentication/basicAuthentication' -Location " WebSite/$($_.User)" -Name realm -Value 'company.com'
Add-WebConfiguration -Filter '/system.webServer/webdav/authoringRules' -Location " WebSite/$($_.User)" -Value @{path="*";users="company\$($_.User)";access="Read,Write,Source"} 
}
1

There are 1 best solutions below

4
Lex Li On

It is obvious slow, because for each of the Set-x lines IIS configuration is read, modified and saved.

If you use the new IISAdministration cmdlets and get an instance of ServerManager to modify the settings, you can save all changes in one shot and it is much quicker when you have tons of settings to update,

https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10/iisadministration-powershell-cmdlets#iisadministration-overview