Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Settings
- $Host.UI.RawUI.WindowTitle = 'Robocopy migration script'
- $datum = Get-Date -Format "MM-dd-yyyy-hh-mm-ss"
- $options = @("/S", "/MT[:4]") # Robocopy arguments for mor see robocopy /?
- #Path settings
- $src = "C:\Test" # Source Path
- $dest = "C:\Test2d" # Destination Path
- $logpath = $dest+"\" # Logfile Path
- $logname = "Logfile_"+$datum+".log" # Logfile Name
- $log = @($logpath+$logname)
- #Exclusion
- $excludeFilename = @("*Kopie*.*", "~$*.*", "*x0*", "*copy*.*") # Exclude file with given name
- $excludeFolder = @("Archiv", "alt") # Exclude folder with given name
- #Extension Filters
- $word = @("*.docx", "*.docm", "*.doc") # Word extension that will be copied
- $excel = @("*.xlsx", "*.xlsm", "*.xls") # Excel extension that will be copied
- $powerpoint = @("*.pptx", "*.pptm", "*.ppt") # PowerPoint extension that will be copied
- $visio = @("*.vsdx", "*.vsdm", "*.vsd") # Visio extension that will be copied
- $pdf = @("*.pdf") # PDF extension that will be copied
- #$tempeplates = @("*.dotx", "*dot", "*.xltx", "*xlt", "*.potx", "*pot") # Templates extension that coud be copied too
- #Start
- Write-Output `n "Start Robocopy Script in 5 Seconds"`n
- Start-Sleep -s 5
- #Check if source and destination path exist
- If (-not (Test-Path $src)) {
- Write-Output "The path '$src' does not exist. Script has stopped!"`n
- break
- }
- If (-not (Test-Path $dest)) {
- new-item -path $dest -type "directory" | Out-Null
- Write-Output "The folder '$dest' has been created"`n
- }
- #Create Logfile
- new-item -path $log -type "file" | Out-Null
- Write-Output "The $logname has been created in $logpath"`n
- #Create command
- $cmdArgs = @($src, $dest, $word, $excel, $visio, $powerpoint, $pdf, $options)
- #Run robocopy command
- Write-Output "Copy files from '$src' to '$dest'"`n
- robocopy @cmdArgs /XF $excludeFilename /XD $excludeFolder /LOG:$log | Out-Null
- #Exit
- Write-Output "Job complete"
- Start-Sleep -s 15
- $host.Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement