Link to home
Start Free TrialLog in
Avatar of uwaadmin
uwaadmin

asked on

Script to check log file location of each site in IIS7

I have a simple script that will go in and purge log files older than x on IIS7 servers but it assumes that the default log location is used inetpub\Logs\LogFiles. I need a script that will check the log file location setting for each site so I don't have to go and manually do it myself.
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Try this:


Import-Module WebAdministration

$yourwebsitename="YourWebsiteName"
 
$website = Get-Item IIS:\Sites\$yourwebsitename
 $LogFileDirectory = $website.logfile.directory
 
if ($LogFileDirectory -match "(%.*%)\\") {
 $LogFileDirectory = $LogFileDirectory -replace "%(.*%)\\","$(cmd /C echo $matches[0])"
 }
Avatar of uwaadmin
uwaadmin

ASKER

I am no scripter so bear with me. From what I can tell this would require me to enter each websites name manually each time I ran it? I don't know all the website names so I would have to log into each server and find out the name of the site to be able to populate it into the script and if I had to do that I could just check log file location while gathering website names.
ASKER CERTIFIED SOLUTION
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, let me give this a whirl.
Worked! Thanks!