How can I change the directory for IIS Advanced Log using powershell

We are using the IIS Advanced Logging module for our IIS site.  I was able to figure out how to setup the main settings from Google searching.  Main one I referenced is here:

However, I can't find a way to programmatically change the log directory for that specific log definition.  When I edit the value through the IIS Mgmt Console UI, it adds an entry in the system.applicationHost/Sites/<MySite> section in the applicationHost.config file.  See the "advancedLogging" entry at the end of the site's section sampled below.

Changing directory in IIS Console UI
<site name="MySite" id="2" serverAutoStart="true">
                <application path="/" applicationPool="MyAppPool">
                    <virtualDirectory path="/" physicalPath="Z:\MySite\Application Server" />
                    <virtualDirectory path="/Serengeti" physicalPath="Z:\AutoRedirect" />
                <application path="/WebServices" applicationPool="Tracker">
                    <virtualDirectory path="/" physicalPath="Z:\MySite\Application Server\WebServices" />
                    <binding protocol="http" bindingInformation="*:80:" />
                <applicationDefaults preloadEnabled="true" />
                <advancedLogging directory="Z:\AdvancedLogging" />

Open in new window

I've tried all sorts of versions of Add-WebConfiguration, Set-WebConfiguration, Set-WebConfigurationProperty.  None work, or I get the config section locked issue.  Which I tried using the ServerManager assembly to try and unlock it, no luck.

The interesting thing is, after setting the path in the UI, if I try using the Get-WebConfigurationProperty to validate the setting in powershell:
(Get-WebConfiguration -Filter /system.applicationHost/sites/sitedefaults/advancedLogging -Location Tracker).Attributes

Open in new window

It shows as the server default value %SystemDrive%\inetpub\logs\AdvancedLogs.  The only way I've been able to get the accurate value is by using the Get-Website cmdlet and drilling into the properties of the returned site object.

Does anyone know how I can change the log directory for IIS Advanced Logging?  I'm trying to work this into server deployment automation.

Server is Windows 2012 R2


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan McFaddenSystems EngineerCommented:
OK, so in Windows Server 2012 R2 (IIS 8.5) Advanced Logging is referred to as Enhanced Logging.  It has the old Advanced Logging functionality built-in.

- Request Header
- Response Header
- Server Variable

You can use the standard HTTP Logging functionality of IIS and include additional enhanced fields in the logs.

Reference link:

You can work with the feature's properties via the *.ItemProperty commands.



Then all you will be doing is relocating the HTTP Logs with is easy enough to do via PowerShell.

Import-Module WebAdministration
Get-WebSite | %{Set-ItemProperty "IIS:\Sites\$($" -name  -value $logPath}

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PberSolutions ArchitectCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Dan McFadden (https:#a42434661)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Experts-Exchange Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.