PoshCode Archive  Artifact [dcff787666]

Artifact dcff787666c15d5be7427511a57944e26cc2a95f5959f99441430e9668860be1:

  • File Get-IISLogLocation.ps1 — part of check-in [8b8313da9d] at 2018-06-10 13:09:13 on branch trunk — This advanced function can be run against a single server or multiple servers to find the location of the log files for each website configured in IIS. This has been tested against II6 and IIS7. (user: Boe Prox size: 2367)

# encoding: ascii
# api: powershell
# title: Get-IISLogLocation
# description: This advanced function can be run against a single server or multiple servers to find the location of the log files for each website configured in IIS. This has been tested against II6 and IIS7.
# version: 0.1
# type: function
# author: Boe Prox
# license: CC0
# function: Get-IISLogLocation
# x-poshcode-id: 2373
# x-archived: 2010-11-23T15:13:27
#
#
Function Get-IISLogLocation {
<#  
.SYNOPSIS  
    This function can be ran against a server or multiple servers to locate
    the log file location for each web site configured in IIS.
.DESCRIPTION
    This function can be ran against a server or multiple servers to locate
    the log file location for each web site configured in IIS.    
.PARAMETER computer
    Name of computer to query log file location.
.NOTES  
    Name: Get-IISLogLocation
    Author: Boe Prox
    DateCreated: 11Aug2010 
         
.LINK  
    http://boeprox.wordpress.com
.EXAMPLE  
Get-IISLogLocation -computer 'server1'

Description
-----------
This command will list the IIS log location for each website configured on 'Server1'
          
#> 
[cmdletbinding(
    SupportsShouldProcess = $True,
	DefaultParameterSetName = 'computer',
	ConfirmImpact = 'low'
)]
param(
    [Parameter(
        Mandatory = $False,
        ParameterSetName = 'computer',
        ValueFromPipeline = $True)]
        [string[]]$computer      
)
Begin {
    $report = @()
    }
Process {
    ForEach ($c in $Computer) {

            If (Test-Connection -comp $c -count 1) {
                
                $sites = [adsi]"IIS://$c/W3SVC"
                $children = $sites.children
                ForEach ($child in $children) {
                    
                    If ($child.KeyType -eq "IIsWebServer") {
                        $temp = "" | Select Server, WebSite, LogLocation
                        $temp.Server = $c
                        $temp.WebSite = $child.ServerComment
                        $temp.LogLocation = $child.LogFileDirectory                           
                        }                                     
                    $report += $temp                        
                    }
            }                
        } 
    }
End {
    $report
    }
}