Home
%3CLINGO-SUB%20id%3D%22lingo-sub-693737%22%20slang%3D%22en-US%22%3EScript%20to%20copy%20specified%20IIS%20logs%20from%20multiple%20Servers%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-693737%22%20slang%3D%22en-US%22%3E%3CH1%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20inherit%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoe%20ui%20light%26amp%3Bquot%3B%2C%26amp%3Bquot%3Bsegoe%20ui%26amp%3Bquot%3B%2Ctahoma%2Carial%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Csans-serif%3B%20font-size%3A%2036px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20normal%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%201.1%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%20margin%3A%2020px%200px%2010px%200px%3B%22%20id%3D%22toc-hId-1964019148%22%20id%3D%22toc-hId-1964019203%22%3ESummary%3C%2FH1%3E%0A%3CP%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoe%20ui%26amp%3Bquot%3B%2Ctahoma%2Carial%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Csans-serif%3B%20font-size%3A%2014px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20400%3B%20letter-spacing%3A%20normal%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%20margin%3A%200px%200px%2010px%200px%3B%22%3ENeed%20to%20copy%20a%20set%20of%20IIS%20logs%20from%20multiple%20servers%20for%20data%20analysis%3F%20Are%20you%20doing%20it%20manually%3F%26nbsp%3B%20If%20so%2C%20please%20check%20out%20this%20script%20as%20it%20will%20help%20expedite%20the%20process.%3C%2FP%3E%0A%3CH1%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20inherit%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoe%20ui%20light%26amp%3Bquot%3B%2C%26amp%3Bquot%3Bsegoe%20ui%26amp%3Bquot%3B%2Ctahoma%2Carial%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Csans-serif%3B%20font-size%3A%2036px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20normal%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%201.1%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%20margin%3A%2020px%200px%2010px%200px%3B%22%20id%3D%22toc-hId--588137813%22%20id%3D%22toc-hId--588137758%22%3EThe%20Script%3A%3C%2FH1%3E%0A%3CPRE%20style%3D%22background-color%3A%20%23f5f5f5%3B%20border-bottom-left-radius%3A%204px%3B%20border-bottom-right-radius%3A%204px%3B%20border-image-outset%3A%200%3B%20border-image-repeat%3A%20stretch%3B%20border-image-slice%3A%20100%25%3B%20border-image-source%3A%20none%3B%20border-image-width%3A%201%3B%20border-top-left-radius%3A%204px%3B%20border-top-right-radius%3A%204px%3B%20box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20display%3A%20block%3B%20font-family%3A%20Menlo%2CMonaco%2CConsolas%2C%26amp%3Bquot%3B%20courier%20new%26amp%3Bquot%3B%2Cmonospace%3B%20font-size%3A%2013px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20400%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%201.4285%3B%20orphans%3A%202%3B%20overflow%3A%20auto%3B%20overflow-wrap%3A%20break-word%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20pre%3B%20word-break%3A%20break-all%3B%20word-spacing%3A%200px%3B%20padding%3A%209.5px%3B%20margin%3A%200px%200px%2010px%200px%3B%20border%3A%201px%20solid%20%23cccccc%3B%22%3E%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%23Modify%20Inputs%3C%2FSPAN%3E%0A%0A%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%23%20Host%20and%20Drive%20to%20store%20the%20IISLogs%0A%24Hostdir%20%3D%20%3CSTRONG%20style%3D%22box-sizing%3A%20border-box%3B%20font-weight%3A%20bold%3B%22%3E%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23ff0000%3B%22%3E%22%5C%5CHOSTSERVER%5Cc%24%22%20%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FSPAN%3E%0A%0A%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%23%20Actual%20Location%20of%20the%20IIS%20Logs%20on%20the%20Server%0A%24iislogsfolder%20%3D%20%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23ff0000%3B%22%3E%3CSTRONG%20style%3D%22box-sizing%3A%20border-box%3B%20font-weight%3A%20bold%3B%22%3E%22c%24%5Cinetpub%5Clogs%5CLogFiles%5CW3SVC1892304237%22%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%0A%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%23A%20wild%20card%20parameter%20to%20determine%20a%20file%20range%0A%24thefiles%20%3D%20%3CSTRONG%20style%3D%22box-sizing%3A%20border-box%3B%20font-weight%3A%20bold%3B%22%3E%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23ff0000%3B%22%3E%22*ex1906*%22%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FSPAN%3E%0A%0A%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%23%20Create%20a%20target%20folder%20on%20host%20if%20does%20not%20exist%0A%26nbsp%3B%24TARGETROOT%20%3D%20%22%24Hostdir%5Clogs%22%0A%26nbsp%3Bif(!(Test-Path%20-Path%26nbsp%3B%20%24TARGETROOT))%7B%0A%26nbsp%3BNew-Item%20-ItemType%20directory%20-Path%26nbsp%3B%20%24TARGETROOT%0A%26nbsp%3B%7D%3C%2FSPAN%3E%0A%0A%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%23%20Create%20an%20export%20folder%20if%20it%20does%20not%20exist%0A%24target%20%3D%20%22%24Hostdir%5Clogs%5Cexport%22%0A%26nbsp%3Bif(!(Test-Path%20-Path%26nbsp%3B%20%24target))%7B%0A%26nbsp%3BNew-Item%20-ItemType%20directory%20-Path%20%24target%0A%26nbsp%3B%7D%3C%2FSPAN%3E%0A%0A%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%23Simple%20Server%20list%0A%24servers%20%3D%20Get-Content%20C%3A%5Cservers.txt%3C%2FSPAN%3E%0A%0A%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%23%20For%20loop%20to%20do%20the%20work%0Aforeach%20(%24server%20in%20%24servers)%0A%7B%3C%2FSPAN%3E%0A%0A%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%23make%20a%20new%20folder%20by%20server%20name%20if%20it%20does%20not%20exist%0A%26nbsp%3B%24TARGETDIR%20%3D%20%22%24target%5C%24Server%22%0A%26nbsp%3Bif(!(Test-Path%20-Path%26nbsp%3B%20%24TARGETDIR))%7B%0A%26nbsp%3BNew-Item%20-ItemType%20directory%20-Path%20%24TARGETDIR%0A%26nbsp%3B%7D%3C%2FSPAN%3E%0A%0A%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%23Get%20the%20files%0A%24iislogLogDir%20%3D%20%22%5C%5C%24server%5C%24iislogsfolder%22%0A%24iislogName%20%3D%20Get-ChildItem%20%22%24iislogLogDir%22%20-Recurse%20-Include%20%22%24thefiles%22%20%7C%20Get-Item%3C%2FSPAN%3E%0A%0A%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%23Start%20a%20loop%20to%20copy%20all%20the%20files%20to%20the%20host%20locatiion%0Aforeach%20(%24log%20in%20%24iislogName)%20%7B%0Acopy-Item%20-path%20%24log%20%24TARGETDIR%0A%7D%3C%2FSPAN%3E%0A%0A%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%7D%0A%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CH1%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20inherit%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoe%20ui%20light%26amp%3Bquot%3B%2C%26amp%3Bquot%3Bsegoe%20ui%26amp%3Bquot%3B%2Ctahoma%2Carial%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Csans-serif%3B%20font-size%3A%2036px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20normal%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%201.1%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%20margin%3A%2020px%200px%2010px%200px%3B%22%20id%3D%22toc-hId-1154672522%22%20id%3D%22toc-hId-1154672577%22%3EWhat%20the%20Script%20Does%3C%2FH1%3E%0A%3CP%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoe%20ui%26amp%3Bquot%3B%2Ctahoma%2Carial%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Csans-serif%3B%20font-size%3A%2014px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20400%3B%20letter-spacing%3A%20normal%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%20margin%3A%200px%200px%2010px%200px%3B%22%3EYou%20only%20need%20to%20modify%20the%20inputs%20and%20create%20a%20server%20list.%20Then%20the%20script%20will%20do%20the%20following%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%26nbsp%3BUse%20a%20list%20of%20servers%20to%20collect%20the%20data%20from.%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BCreate%20a%20%22logs%22%20folder%20on%20the%20specified%20drive.%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BCreate%20an%20%22export%22%20sub%20folder%20under%20%22logs%22.%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BCreate%20a%20sub%20folder%20under%20%22export%22%20using%26nbsp%3B%20server%20name%20of%20each%20server.%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BUse%20the%20wild%20card%20file%20name%20you%20specified%20to%20target%20specific%20files.%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BCopy%20each%20targeted%20file%20to%20the%20correct%20serer%20name%20folder.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoe%20ui%26amp%3Bquot%3B%2Ctahoma%2Carial%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Csans-serif%3B%20font-size%3A%2014px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20400%3B%20letter-spacing%3A%20normal%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%20margin%3A%200px%200px%2010px%200px%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoe%20ui%26amp%3Bquot%3B%2Ctahoma%2Carial%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Csans-serif%3B%20font-size%3A%2014px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20400%3B%20letter-spacing%3A%20normal%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%20margin%3A%200px%200px%2010px%200px%3B%22%3ENotes%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%26nbsp%3BIf%20you%20want%20to%20collet%201%20file%20from%20each%20server%2C%20just%20specify%20use%20the%20full%20date%20name%20in%20the%20search%20input%20(ie%26nbsp%3B%3CSPAN%20style%3D%22box-sizing%3A%20border-box%3B%22%3E190606%3C%2FSPAN%3E).%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BYou%20can%20run%20this%20more%20than%20once%20if%20another%20file%20is%20needed%20and%20they%20will%20be%20added%20to%20the%20existing%20folders.%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BThe%20%22export%22%20folder%20will%20contain%20all%20the%20files%20needed.%20Just%20compress%20the%20folder%20and%20your%20ready%20to%20share.%3C%2FLI%3E%0A%3C%2FUL%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-693737%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20On-Prem%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Support%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E

Summary

Need to copy a set of IIS logs from multiple servers for data analysis? Are you doing it manually?  If so, please check out this script as it will help expedite the process.

The Script:

#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
}

}
  

What the Script Does

You only need to modify the inputs and create a server list. Then the script will do the following:

  1.  Use a list of servers to collect the data from.
  2.  Create a "logs" folder on the specified drive.
  3.  Create an "export" sub folder under "logs".
  4.  Create a sub folder under "export" using  server name of each server.
  5.  Use the wild card file name you specified to target specific files.
  6.  Copy each targeted file to the correct serer name folder.

 

Notes:

  •  If you want to collet 1 file from each server, just specify use the full date name in the search input (ie 190606).
  •  You can run this more than once if another file is needed and they will be added to the existing folders.
  •  The "export" folder will contain all the files needed. Just compress the folder and your ready to share.