Solved

Script to check log file location of each site in IIS7

Posted on 2014-03-27
5
746 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 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