Guide Programming + Scripting Powershell Create copy of folder/drive on another path, iterate folder name with each copy Updated December 03 2024
Copy to Clipboard $FromPath = "C:\Users\Admin\Desktop\New folder\From" $ToPath = "C:\Users\Admin\Desktop\New folder\To" $FolderPrefix = "Folder-" $Counter = 1 while( ( Test-Path "$($ToPath)\$($FolderPrefix)$($Counter)" ) -eq $true ){ $Counter++ } Write-Host "Creating the folder $($ToPath)\$($FolderPrefix)$($Counter)" New-item -Path "$($ToPath)\$($FolderPrefix)$($Counter)" -ItemType "directory" robocopy /mir /xj /r:0 "$FromPath" "$($ToPath)\$($FolderPrefix)$($Counter)" Write-Host "`r`n`r`n`r`nBackup finished!"


An example batch file to run it:
Copy to Clipboard @echo off PowerShell.exe -ExecutionPolicy Bypass -File "C:\Users\Admin\Desktop\BackupDrive.ps1" echo. echo. echo This backup has finished. You may close this window. pause
Search Keywords: Powershell




©2024 - Some portions of this website are Copyrighted.
Your IP: 18.119.141.115     Referring URL:
Browser: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Terms and Conditions, Privacy Policy, and Security Policy