Powershell command to set IIS logging settings Powershell command to set IIS logging settings powershell powershell

Powershell command to set IIS logging settings


Import-Module WebAdministrationSet-WebConfigurationProperty "/system.applicationHost/sites/siteDefaults" -name logfile.directory -value $logdir


While testing the answer from this thread, toggling options via IIS Manager and PowerShell, I stumbled on something that has been hidden to me. In IIS Manager, choosing Configuration Editor and making a change, allows the IIS Manager to generate and display the script for the change in C#, JavaScript, AppCmd.exe and PowerShell. Just click the Generate Script option.

[Auto Generated Scripts for IIS configuration changes]


For changing an individual web site's logFile configuration, the original post was nearly correct. Instead of New-ItemProperty, use Set-ItemProperty, like so...

Set-ItemProperty "IIS:\Sites\$SiteName" -name logFile -value @{directory=$LogPath}

For changing the server-wide default settings, see Andy Schneider's answer.

For more information about the options available, see this IIS.net article.