#Modify Inputs
# Host and Drive to store the IISLogs
$Hostdir = "\\HOSTSERVER\c$"
# Actual Location of the IIS Logs on the Server
$iislogsfolder = "c$\inetpub\logs\LogFiles\W3SVC1892304237"
#A wild card parameter to determine a file range
$thefiles = "*ex1906*"
# Create a target folder on host if does not exist
$TARGETROOT = "$Hostdir\logs"
if(!(Test-Path -Path $TARGETROOT)){
New-Item -ItemType directory -Path $TARGETROOT
}
# Create an export folder if it does not exist
$target = "$Hostdir\logs\export"
if(!(Test-Path -Path $target)){
New-Item -ItemType directory -Path $target
}
#Simple Server list
$servers = Get-Content C:\servers.txt
# For loop to do the work
foreach ($server in $servers)
{
#make a new folder by server name if it does not exist
$TARGETDIR = "$target\$Server"
if(!(Test-Path -Path $TARGETDIR)){
New-Item -ItemType directory -Path $TARGETDIR
}
#Get the files
$iislogLogDir = "\\$server\$iislogsfolder"
$iislogName = Get-ChildItem "$iislogLogDir" -Recurse -Include "$thefiles" | Get-Item
#Start a loop to copy all the files to the host locatiion
foreach ($log in $iislogName) {
copy-Item -path $log $TARGETDIR
}
}