Tuesday, January 12, 2010

copying of folders and subfolders from one location to another using powershell

There has been a need to copy folders and subfolders inside from one location to another. I have used powershell to do the same. First by creating a new folder and then copying the files, folders and sub folders inside that new folder.
-----------------------------
$server1 = "Server1"
$tofolder = "NewFolderName"
$fromfolder = "OldFolderName"
$frompath = "
\\server2\OldLocation"
$topath = "
\\$server1\c$"
New-Item -Name $tofolder -ItemType Directory -Path $topath
Copy-Item -Path $frompath\$fromfolder\* -Destination $topath\$tofolder -Force -Recurse
Write-Host Copying of the latest sharepoint build $tofolder is done

------------
Hope this helps...

No comments:

Post a Comment