There are many scripts out there using a variety of methods to delete IIS logs from servers using PowerShell. These scripts are usually written to run locally on servers, which can have two drawbacks:

In environments with a large number of servers, scheduling and maintaining these scripts can require a significant amount of work;

Depending on the security restrictions on production servers, administrators might not be able to schedule this script to run whether they are logged on to the server or not.

This was the scenario I found recently. In order to overcome both obstacles, I decided to run the script from a “script server” where security settings did not prevent cached credentials. Additionally, by deleting these logs remotely I could
have a single script targeting multiple servers, making it much easier to manage!

As I have mentioned, there are many ways of deleting IIS logs from a server. The method I have been using lately uses the
WebAdministration module and the Get-WebSite cmdlet to get a list of all websites on the local server.

To specify which servers to target, simply update the $excServers array within the script. We could also make this part of user input to allow users to specify which servers to action on more easily. Modules would be the next step :)