Advertisement
PureGremlin

RobocopyReport

Oct 30th, 2023 (edited)
1,138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function RobocopyReport ($logdir,$exportpath) {
  2. $report=@()
  3. gci $logdir  | %{
  4.     $summ= [pscustomobject]@{
  5.         Share = $_.name.trim(".txt")
  6.         Dirs = ($_|gc -last 15|Select-String "Dirs.:").tostring().split(':',2)[-1].trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim()
  7.         Files = ($_|gc -last 15|Select-String "Files.:").tostring().split(':',2)[-1].trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim()
  8.         Bytes = ($_|gc -last 15|Select-String "Bytes.:").tostring().split(':',2)[-1].trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim().split(" ",2).trim()
  9.     }
  10.     $bytesvalues=@()
  11.     $bytesunits=@()
  12.     $summ.Bytes|%{
  13.     [string]$InString = $_
  14.     [double]$OutNumber = $null
  15.     if ([double]::TryParse($InString,[ref]$OutNumber)){
  16.         $bytesvalues+=$OutNumber
  17.     }else {
  18.         $bytesunits+=$_
  19.     }
  20. }
  21.  
  22. $summary=[pscustomobject]@{
  23.     Share=$summ.share
  24.     DirsTotal = $summ.dirs[0]
  25.     DirsCopied = $summ.dirs[1]
  26.     DirsSkipped = $summ.dirs[2]
  27.     DirsMismatch = $summ.dirs[3]
  28.     DirsFAILED = $summ.dirs[4]
  29.     DirsExtras = $summ.dirs[5]
  30.     FilesTotal = $summ.files[0]
  31.     FilesCopied = $summ.files[1]
  32.     FilesSkipped = $summ.files[2]
  33.     FilesMismatch = $summ.files[3]
  34.     FilesFAILED = $summ.files[4]
  35.     FilesExtras = $summ.files[5]
  36.     BytesTotal = $bytesvalues[0]
  37.     BytesCopied = $bytesvalues[1]
  38.     BytesSkipped = $bytesvalues[2]
  39.     BytesMismatch = $bytesvalues[3]
  40.     BytesFAILED = $bytesvalues[4]
  41.     BytesExtras = $bytesvalues[5]
  42.     BytesTotalUnit = $bytesunits[0]
  43.     BytesCopiedUnit = $bytesunits[1]
  44.     BytesSkippedUnit = $bytesunits[2]
  45.     BytesMismatchUnit = $bytesunits[3]
  46.     BytesFAILEDUnit = $bytesunits[4]
  47.     BytesExtrasUnit = $bytesunits[5]
  48.     }
  49.     $report+=$summary
  50. }
  51. $exportfile = $exportpath + "\" + ($logdir.split("\",99))[-1] + ".csv"
  52. $report | export-csv -notypeinformation -path $exportfile
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement