I am trying to: A. copy the current application event log from server A B. copy the current IIS logs from server A c. create a folder with todays date on the network share and copy A and B above into it. Currently I am using two commands in the script to copy the files required but I cannot figure out the create folder date and integrate that into the process... Here is what I am using:

your text#Copies Application Event Log Folder to share your text#Copy-Item -Path "\windowsserver\c$\Windows\System32\winevt\Logs\application.evtx" -Destination your text"\networkshare\folder" -whatif

your text#Copies IIS logs with todays date to share your text$RemotePath = "\servername\d$\LogFiles\W3SVC1" your text$LocalPath = "\networkshare\folder"" your text$Max_days = "-1" your text#Max_mins = "-5" your text$Curr_date = get-date

your text#Checking date and then copying file from RemotePath to LocalPath, which would be the share your textForeach($file in (Get-ChildItem $RemotePath)) your text{ your text if($file.LastWriteTime -gt ($Curr_date).adddays($Max_days)) your text {

your text# Copy-Item -Force -Path $file.fullname -Destination $LocalPath -WhatIf your text Copy-Item -Force -Path $file.fullname -Destination $LocalPath your text# Move-Item -Path $file.fullname -Destination $LocalPath your text } your text ELSE your text {"not copying $file" your text }

your text}

I got this to work this afternoon. Certainly not pretty, but...

 $basedir = "networkshare\report"
 $today   = (Get-Date).ToString('MM_dd_yy')

 $location = New-Item -Path $basedir -Type Directory -Name $today

 Copy-Item 
 '\\windowsserver\c$\Windows\System32\winevt\Logs\application.evtx' - 
 Destination $location

 $EarliestModifiedTime = (Get-Date).AddDays(-1).Date     # 12AM 
 yesterday
 $LatestModifiedTime = (Get-Date).Date                   # 12AM today
 Get-ChildItem "\\windowsserver\d$\LogFiles\W3SVC1\*.*" -File |
 ForEach-Object {
    if ( ($_.CreationTime -ge $EarliestModifiedTime) -and 
 ($_.CreationTime -lt $LatestModifiedTime) ){   # i.e., all day 
 yesterday
        Copy-Item $_ -Destination $location
        Write-Host "Copied $_"
    }
    else {
        Write-Host "Not copying $_"
    }
 }

Your assistance and input is greatly appreciated. Tony

I tried several different things from doing the good ole google search. I could create a folder with todays date in the destination, but could not figure out how to use that to get both A and B into there. My brain is not wired for for this somehow...

0

There are 0 best solutions below