I'm working a script where I'd like to copy logs from a hosts vmfs-based scratchconfig location to a CIFS (network) share. However, similar to the robocopy utility where it only moves newer files to the destination, I'd like to somehow do that around the Copy-DatastoreItem cmdlet.
Connect-VIServer hostname -User "user" -Password "password"
$datastore = Get-Datastore "DS Name"
New-PSDrive -Location $datastore -Name ds -PSProvider VimDatastore -Root "\"
Set-Location ds:\
$source = get-childitem ds:\log\
$target = Get-ChildItem \\network\share\
ROBOCOPY $source $target *.* /E /COPYALL | out-file C:\temp\LogReport.txt -Append
Disconnect-VIServer -hostname -Confirm:$false
Unfortunately, robocopy doesn't ingest the $source & $target directory paths as I'd hoped and thus fails - so I’m wondering if there’s a suitable replacement for robocopy in this regard. I'm using PowerCLI 5.0 build 435427. Thanks in advance.
As I think this through, I may have thought up an easier way to move these files - albeit not as elegent. I'll just copy all of the files from the vmfs datastore to a local directory. Then I'll just disconnect and, from there, launch the robocopy at the end of the script and manipulate the source/destination content.
The VimDatastore provider is somewhat limited in what it allows you to do.
Did you try with the Copy-Item cmdlet and a filter (Where-clause) on the LastWriteTime proprty ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, LucD- I'm going to research using the Copy-Item cmdlet now because I just discovered that the Copy-DatastoreItem cmdlet does not retain the date/timestamp after copying to its destination. Thus my plan of following up with robocopy to do the comparison will not work since these original timestamps are not retained.