Moving files up a folder level

Moving files up a folder level

In the past I’ve used this small snippet to move tons of files and folders up a level. <# .SYNOPSIS Moves all subfolders in Source to same

Removing an installed Windows Update
Testing SSL and TLS with PowerShell
Create Local Administrator Account Remotely

In the past I’ve used this small snippet to move tons of files and folders up a level.

<#
.SYNOPSIS
Moves all subfolders in Source to same-named parent folder in Destination

.DESCRIPTION
Current directory is like N:\Folder1\Folder2\
As an example to move all folder and files in “folder2” up under N:\, to be like “N:\Folder2”
$Source = “N:\Folder1\Folder2\”
$destination= “N:”

.NOTES
File Name : MoveUpLevel.ps1
Author : Jeff Holder
Date : 02/21/2018
Requires : PowerShell V3
#>

$source = “N:\myserver\daily\”
$destination = “N:\”
$items = Get-ChildItem $source -Recurse
Foreach ($item in $items){
Try
{
$folder = Split-path -path $item.directoryname -leaf
Write-Host “Moving File:” $item.FullName
$moveto = $destination+$folder
write-host “Moving to Destination: $moveto”
Move-Item -Path $item.fullname -Destination $moveto -Force
}
catch {}
}

COMMENTS

WORDPRESS: 0