Andrew Beaumont Andrew Beaumont - 2 months ago 6x
PowerShell Question

Move-item "the path is not supported."

We have a script which is successfully compressing folders to 7z and then deleting the folder once it has been compressed.
What we would like to do is move the compressed 7z file to another location which is on cheaper storage and also for backup / offsite archiving purposes.

I've tried the below but I'm getting an error "the path is not supported."

Is anyone able to assist?

Get-ChildItem 'E:\AbleyTest\TestFolder\_Archived\*' | Where-Object {
} | Select-Object -Expand FullName | ForEach-Object {
& 7z.exe a -mx=9 -t7z "$_.7z" "$_"
if ($LastExitCode -eq 0) {
$folder = (Get-Item $_).Parent.Parent.Name
if (Test-Path "e:\archived\$folder") {
Move-Item -Path "$_.7z" -Destination "e:\archived\$folder\$_.7z"
} else {
New-Item "e:\archived\$folder" -Type directory
Move-Item -Path "$_.7z" -Destination "e:\archived\$folder\$_.7z"
Remove-Item -Path $_ -Force -Recurse
} else {
Add-Content "e:\scripts\archivelog $(get-date -f dd-MM-yyyy).txt" "$_ ran into error $LastExitCode while archiving"


Your destination path is not valid. Consider that $_ is the full path to some folder (such as E:\AbleyTest\TestFolder\_Archived\SomeFolder, your destination path of:


suddenly becomes:


Edit: I just realized that I told you the problem, but didn't really help you solve it. The destination path doesn't need the name of the file (it retains the file name to use at the destination), so simply stop after $folder, and you should be just fine:

Move-Item -Path "$_.7z" -Destination "e:\archived\$folder"