I am trying to create a mechanism (in my case Robocopy wrapped in PowerShell) that will back up IIS logs from all of our web servers into a central CIFS share. As you'd expect, I've had issues with copying the currently open log file, since NTFS doesn't tend to reliably update the LastWriteTime as the file is written to unless all the handles to it are closed.
I'd noticed however that any time I browsed the directory with Windows Explorer not only would the Date Modified update but the next Robocopy run would properly catch the file and bring it current. At an attempt to emulate the Windows Explorer behavior, I ran the following code in PowerShell before invoking the Robocopy job:
$aryFileList = Get-ChildItem $job.SourcePath
ForEach ($file in $aryFileList) {(New-object System.IO.FileInfo $file).LastWriteTime | Out-Null}
This worked for some of my IIS servers and all of my other logging methods (mostly log4net). However, on two of my IIS servers this had no effect, even though they are the same OS and IIS version as others that it worked perfectly on.
This leads me back to the thought; what exactly does Windows Explorer do when you use it to refresh a directory to the point that it updates the Date Modified / LastWriteTime info? Most importantly to my purposes, is there any way that the same thing can be invoked in PowerShell?
Refresh
method ofSystem.IO.FileInfo
?Refresh()
refreshes it only for a process, not system-wide. What are the values of these keys in your PC's registry - technet.microsoft.com/en-us/library/ff686200%28v=ws.10%29.aspx ?Get-SmbClientConfiguration
should report everything SMB-related.Set-SmbClientConfiguration -FileInfoCacheLifetime 0
will set cache lifetime to zero, replace0
to10
to restore default. Mind to try it on test machine to see if it does forcerobocopy
and other client-side processes to always get latest data from network share?