Solved

Script to check log file location of each site in IIS7

Posted on 2014-03-27
5
628 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 18

Expert Comment

by:Raheman M. Abdul
Comment Utility
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
Comment Utility
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 18

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
Comment Utility
# 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
Comment Utility
Thanks, let me give this a whirl.
0
 

Author Comment

by:uwaadmin
Comment Utility
Worked! Thanks!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now