I am trying to move one folder and its content from 1 location to another. Name of the folder is c:\logfiles and it has sub folders and text files, but the script which i have written, it only moves the content of logfiles but i want to move logfiles folder as a whole to a new location
$current_logfiles = 'C:/LogFiles/*'
$new_logfiles = 'C:\My_Project\LogFiles\'
if (!(Test-Path -path $new_logfiles )) {
New-Item $new_logfiles -type directory
Move-Item -Path $current_logfiles -Destination $ $new_logfiles -Recurse -force
}
It's because you have the *
, you're telling it to move everything under C:\LogFiles
.
This should work:
$current_logfiles = 'C:\LogFiles'
$new_logfiles = 'C:\My_Project\LogFiles'
if (!(Test-Path -path $new_logfiles)) {
Move-Item -Path $current_logfiles -Destination $new_logfiles -force
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With