Solved

Script to check log file location of each site in IIS7

Posted on 2014-03-27
5
688 Views
Last Modified: 2014-04-10
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.
0
Comment
Question by:uwaadmin
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39960137
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])"
 }
0
 

Author Comment

by:uwaadmin
ID: 39960444
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.
0
 
LVL 19

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
ID: 39960459
# This will collect all sites and get the log file location and stores the log locations in a c:\logfiles.txt file.

$websites = get-website
foreach ($website in $websites)
{  $websitename=$website.Name
$websiteinfo = Get-Item IIS:\Sites\$websitename
 $LogFileDirectory = $websiteinfo.logfile.directory
 
if ($LogFileDirectory -match "(%.*%)\\") {
 $LogFileDirectory = $LogFileDirectory -replace "%(.*%)\\","$(cmd /C echo $matches[0])" | add-content c:\logfiles.txt

 }
0
 

Author Comment

by:uwaadmin
ID: 39961510
Thanks, let me give this a whirl.
0
 

Author Comment

by:uwaadmin
ID: 39991971
Worked! Thanks!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question