Share via


move-item asks for path[0]

Question

Tuesday, March 24, 2015 3:36 PM

I have the following script that Im trying to use based on a posting from June Blender in 2013.

$archivedate = (Get-Date).AddDays(-61)
$files = get-childitem -recurse E:\ftp-folder\UFSI-VA-WAVE-back |
 where-object {$_.lastWriteTime -lt $ArchiveDate}
foreach ($file in $files)
{
 $newName = $file.fullname -Replace 'E:\ftp-folder','F:\archive'
 move-item -Destination $newname
}

when I run it, powershell gives me this:

cmdlet Move-Item at command pipeline position 1
Supply values for the following parameters:
Path[0]: PS C:\Scripts>
PS C:\Scripts> .\move-back61.ps1

cmdlet Move-Item at command pipeline position 1
Supply values for the following parameters:
Path[0]:

why doesn't it find the path of the current $file?

Thanks!

Steve

All replies (4)

Tuesday, March 24, 2015 4:08 PM ✅Answered

The original w2asw about renaming a file and no moving it as you are doing.

Here is the correct code for what you are doing:

$archivedate = (Get-Date).AddDays(-61)
$files = get-childitem -recurse E:\ftp-folder\UFSI-VA-WAVE-back |  
     where-object {$_.lastWriteTime -lt $ArchiveDate} |
     move-item -Destination F:\archive
 

Just do it in the pipeline and it will be moved.

Don't use double slashes.

This will not preserve the folder structure at the target the same as you example.  To move file with folder structure use RoboCopy.

Post RC questions in the storage management forum.

RoboCopy  E:\ftp-folder\UFSI-VA-WAVE-back F:\archive *.8 -E -MinAGE 61 /MOV

¯\(ツ)_/¯


Tuesday, March 24, 2015 3:39 PM

Hi Steve,

Because you haven't told it where the source file is. Use $file.FullName as the -Path parameter.

Don't retire TechNet! - (Don't give up yet - 13,225+ strong and growing)


Tuesday, March 24, 2015 4:14 PM

Thank you so much. This worked.


Tuesday, March 24, 2015 4:15 PM

Hi Mike,

Thanks for the reply. I tried that but, it seems to be adding a ":FileInfo" to the end of the file name.

I appreciate your quick response.