Change folder location using powershell

$Time=get-date -uformat “%Y-%m-%d@%H-%M-%S”

$location=”C:\backupfolder”

$backuplocation = “c:\Backup\”
Copy-Item $location -destination $backuplocation -recurse

$copyfoldername=Get-ChildItem $backuplocation |
Where-Object { $_.PSIsContainer } | Select-Object -ExpandProperty Name
$source=$backuplocation +  $copyfoldername

$foldernames=Get-ChildItem $source  |
Where-Object { $_.PSIsContainer } | Select-Object -ExpandProperty Name

foreach($foldername in $foldernames)
{

$sources=$source + “\” + $foldername
Rename-Item  -path $sources  -NewName “$foldername$Time”
$sources=””
}

Rename-Item  -path $source  -NewName “$foldername$Time”

Advertisements