Copy-item usage

I am looking to copy the contents of 180 roaming profiles each named as username.domain.V2 to the same directory but change the V2 to V6. I'm not sure if there is a way to do this via powershell as each directory is named differently.
grahamcoAsked:
Who is Participating?
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
#Set the variable for where the path
$parentFolder = "C:\Temp";

#Get an array only folder that ends with V2
$dir = dir "$($parentFolder)" | ?{$_.PSISContainer -And $_.Name.EndsWith("V2")}

#Loop through folder
foreach ($d in $dir){
    #Build robocopy command
    Robocopy "$($d.FullName)" "$($d.FullName.Replace("V2","V6"))" /E /XO /ZB /COPYALL
}

Open in new window

0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
$parentFolder = "C:\Temp";
$dir = dir "$($parentFolder)" | ?{$_.PSISContainer -And $_.Name.EndsWith("V2")}

foreach ($d in $dir){
    Robocopy "$($d.FullName)" "$($d.FullName.Replace("V2","V6"))" /E /XO /ZB /COPYALL
}

Open in new window

0
 
ITguy565Commented:
Simple script but it should work for you.

robocopy c:\test c:\test1\ /e
set-location c:\test1\
get-childitem *.v2 | % { Rename-Item $_ $_.Name.Replace(".v2",".v6") }

Open in new window

0
 
grahamcoAuthor Commented:
Thank you Shaun your script worked as-is minus updating the paths. If you have a moment can you explain what each line is doing? especially that second line.
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
Confirmed working by OP
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.