none
Counting Exchange Transaction Logs RRS feed

  • Question

  • Trying to come up with a .ps1 that counts log files generated by Exchange (multiple DB's on multiple servers) on an as needed basis between backups.  Input file is a .csv of the format:

    Server,DBName
    server1,exdb11
    server1,exdb12
    server2,exdb21
    server2,exdb22

    Here is what I thought should work but gives me "token 'in'" errors on the ForEach or is not accepting the input to determine the network path to the file locations.

    $PathNames = (Import-csv C:\ExServerDBs.csv)
      ForEach-Object ($P in $PathNames)
        {
          $ExDBLogPath = "\\" + $_.Server + "\d$\ExchangeLogs\" + $_.DBName
          (Get-ChildItem -Path $ExDBLogPath -filter "*.log").Count
        }

    Any help insight or suggestions would be greatly appreciated.

    Thanks!


    KYPaul

    Tuesday, September 2, 2014 1:06 PM

Answers

  • Why aren't you just using the Exchange DB statistics report?

    You are usingthe wrong "ForEach".

    See: help about_foreach

    Import-csv C:\ExServerDBs.csv |
       ForEach-Object{
           $ExDBLogPath="\\$($_.Server)\d$\ExchangeLogs\$($_.DBName)\*"
           (Get-ChildItem -Path $ExDBLogPath -filter *.log).Count
         }
    
    


    ¯\_(ツ)_/¯

    • Marked as answer by KYPaul Tuesday, September 2, 2014 6:09 PM
    Tuesday, September 2, 2014 1:26 PM

All replies

  • Why aren't you just using the Exchange DB statistics report?

    You are usingthe wrong "ForEach".

    See: help about_foreach

    Import-csv C:\ExServerDBs.csv |
       ForEach-Object{
           $ExDBLogPath="\\$($_.Server)\d$\ExchangeLogs\$($_.DBName)\*"
           (Get-ChildItem -Path $ExDBLogPath -filter *.log).Count
         }
    
    


    ¯\_(ツ)_/¯

    • Marked as answer by KYPaul Tuesday, September 2, 2014 6:09 PM
    Tuesday, September 2, 2014 1:26 PM
  • That did it!  I will take a look at the Exchange DB statistics report.

    Thanks very much!


    KYPaul

    Tuesday, September 2, 2014 6:09 PM