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: https://rafpe.ninja/2015/08/05/iis-advanced-logging-first-approach/

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>
                <application path="/WebServices" applicationPool="Tracker">
                    <virtualDirectory path="/" physicalPath="Z:\MySite\Application Server\WebServices" />
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation="*:80:" />
                </bindings>
                <applicationDefaults preloadEnabled="true" />
                <advancedLogging directory="Z:\AdvancedLogging" />
</site>

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

Thanks.

Jeff
Serengeti-AdminAsked:
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:  https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-85/enhanced-logging-for-iis85

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

Get-ItemProperty
Set-ItemProperty
New-ItemProperty

Link:  https://forums.iis.net/p/1205491/2064115.aspx?Re+Add+IIS+8+5+Custom+Logging+Fields+with+Powershell

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)" -name logFile.directory  -value $logPath}

Open in new window


Dan
0

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.

Pber
Experts-Exchange Cleanup Volunteer
0
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
Powershell

From novice to tech pro — start learning today.