none
Changing mutliple IIS 7 website logfile locations via PSH RRS feed

  • Question

  • I'm trying to figure out how to do two things in the IIS PowerShell Management SnapIn:

    • Print a list of all site names and the path of each site's log files
    • Loop through all sites and change the location of the log files to a data drive instead of C:

    For the first question, I was able to find the site's logFile property, but can't seem to get at the logFile.directory property.

    For the second part, I found an article that describes how to change a single site's logFile.directory property, but I'm stuck trying to do it for multiple sites at once. Here's what I have so far:

    Get-ChildItem | Foreach-Object {Set-ItemProperty $_.Name -name logFile.directory -value 'E:\Logs'}

    But that throws several errors and then exits.

    Any suggestions?

    Thanks,

    Josh

    Friday, August 20, 2010 4:16 PM

Answers

  • Changing the log location:

    Function Set-IISLogLocation {
    <# 
    .SYNOPSIS 
      
    .DESCRIPTION
      
    .PARAMETER computer
      Name of computer
    .NOTES 
      Name: Set-IISLogLocation
      Author: Boe Prox
      DateCreated: 20Aug2010 
         
    .LINK 
      http://boeprox.wordpress.com
    .EXAMPLE 
      Set-IISLogLocation -computer <server> -logdir "D:\logs"
         
    #> 
    [cmdletbinding(
      SupportsShouldProcess = $True,
    	DefaultParameterSetName = 'computer',
    	ConfirmImpact = 'low'
    )]
    param(
      [Parameter(
        Mandatory = $False,
        ParameterSetName = 'computer',
        ValueFromPipeline = $True)]
        [string]$computer,
      [Parameter(
        Mandatory = $False,
        ParameterSetName = 'computer',
        ValueFromPipeline = $False)]
        [string]$logdir         
    )
    
    $report = @()
    
    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") {
              If ($pscmdlet.ShouldProcess($($child.servercomment))) {
                $child.Put("LogFileDirectory",$logdir)
                $child.SetInfo()
                }        
              $temp = New-Object PSObject
              $temp | Add-Member NoteProperty Server $c
              $temp | Add-Member NoteProperty WebSite $child.ServerComment
              $temp | Add-Member NoteProperty LogType $child.LogFileDirectory                   
              }
            Else {
            $temp = New-Object PSObject
              }          
            $report += $temp            
            }
        }        
      }               
    $report
    }
    
    Friday, August 20, 2010 6:54 PM

All replies

  • This doesn't use the IIS Management SnapIn, and it has only been tested on IIS6, but may work for you.  It will list out the logfile directories.  Still working on the change directory portion...

    Function Get-IISLogLocation {
    <# 
    .SYNOPSIS 
      
    .DESCRIPTION
      
    .PARAMETER computer
      Name of computer
    .NOTES 
      Name: Get-IISLogLocation
      Author: Boe Prox
      DateCreated: 11Aug2010 
         
    .LINK 
      http://boeprox.wordpress.com
    .EXAMPLE 
    
         
    #> 
    [cmdletbinding(
      SupportsShouldProcess = $True,
    	DefaultParameterSetName = 'computer',
    	ConfirmImpact = 'low'
    )]
    param(
      [Parameter(
        Mandatory = $False,
        ParameterSetName = 'computer',
        ValueFromPipeline = $True)]
        [string]$computer   
    )
    
    $report = @()
    
    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 = New-Object PSObject
              $temp | Add-Member NoteProperty Server $c
              $temp | Add-Member NoteProperty WebSite $child.ServerComment
              $temp | Add-Member NoteProperty LogLocation $child.LogFileDirectory               
              }   
            Else {
              $temp = New-Object PSObject
              }                 
            $report += $temp            
            }
        }        
      }               
    $report
    }
    
    • Edited by Boe ProxMVP Friday, August 20, 2010 7:05 PM Update code
    Friday, August 20, 2010 6:38 PM
  • Changing the log location:

    Function Set-IISLogLocation {
    <# 
    .SYNOPSIS 
      
    .DESCRIPTION
      
    .PARAMETER computer
      Name of computer
    .NOTES 
      Name: Set-IISLogLocation
      Author: Boe Prox
      DateCreated: 20Aug2010 
         
    .LINK 
      http://boeprox.wordpress.com
    .EXAMPLE 
      Set-IISLogLocation -computer <server> -logdir "D:\logs"
         
    #> 
    [cmdletbinding(
      SupportsShouldProcess = $True,
    	DefaultParameterSetName = 'computer',
    	ConfirmImpact = 'low'
    )]
    param(
      [Parameter(
        Mandatory = $False,
        ParameterSetName = 'computer',
        ValueFromPipeline = $True)]
        [string]$computer,
      [Parameter(
        Mandatory = $False,
        ParameterSetName = 'computer',
        ValueFromPipeline = $False)]
        [string]$logdir         
    )
    
    $report = @()
    
    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") {
              If ($pscmdlet.ShouldProcess($($child.servercomment))) {
                $child.Put("LogFileDirectory",$logdir)
                $child.SetInfo()
                }        
              $temp = New-Object PSObject
              $temp | Add-Member NoteProperty Server $c
              $temp | Add-Member NoteProperty WebSite $child.ServerComment
              $temp | Add-Member NoteProperty LogType $child.LogFileDirectory                   
              }
            Else {
            $temp = New-Object PSObject
              }          
            $report += $temp            
            }
        }        
      }               
    $report
    }
    
    Friday, August 20, 2010 6:54 PM