none
Script to locate IIS log file locations on remote servers RRS feed

  • Frage

  • Hi All,

    I'm looking for a script that can pull all the IIS log locations from a bunch of servers. I found this 

    Import-Module WebAdministration
    
    foreach($WebSite in $(get-website))
        {
        $logFile="$($Website.logFile.directory)\w3svc$($website.id)".replace("%SystemDrive%",$env:SystemDrive)
        Write-host "$($WebSite.name) [$logfile]"
        } 
    

    But that only seems to work locally and no ide how to incoporate that into a larger script formultiple servers.

    Any help appreciated.


    Thanks - Joe.

    Dienstag, 21. Januar 2020 13:33

Alle Antworten

  • OK, i've figured this far out

    Import-Module webadministration
    
    $Servers = Get-Content -Path "C:\Servers.txt"
    foreach ($comp in $servers) {
    
    
    invoke-command -ComputerName $comp -ArgumentList $comp -credential test\user1 -ScriptBlock {
        param($comp)
    
    foreach($WebSite in $(get-website))
        {
        $logFile="$($Website.logFile.directory)\w3svc$($website.id)".replace("%SystemDrive%",$env:SystemDrive)
        Write-host "$comp,$($WebSite.name), [$logfile]"
        } 
    
        }
    
        }

    The only thing is that for every server in the list it prompts for credentials. Any idea how i get it to ask only once ?

    Thanks - Joe.

    Dienstag, 21. Januar 2020 14:51
  • OK, Now the issue is if I have 30 servers, how do I output all the lists to a text file ?

    Thanks - Joe.

    Dienstag, 21. Januar 2020 15:27
  • The only thing is that for every server in the list it prompts for credentials. Any idea how i get it to ask only once ?
    You store the credential object in a variable before and use this variable in your command line.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Dienstag, 21. Januar 2020 15:51
  • OK, Now the issue is if I have 30 servers, how do I output all the lists to a text file ?
    You pipe it to Out-File or Export-Csv. Please read the complete help including the examples to learn how to use it.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Dienstag, 21. Januar 2020 15:53
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Montag, 27. Januar 2020 07:31
    Moderator