Move files and fullfill other hard disks

Hi all,
i need to move some files from C:\yyyy\ to another hdd, for example D:\ … and the script is working fine.

My problem is that, if possible, i would like the script automatically fullfill D:\ and, if the available space in D is not enough for the file, it move the file to E:, if also E is full to F:, and so on.

Could you help me ?
Thanks a lot


Hello Elio,

Firstly you should calcuate the size of the floder or files.
then use if to judge the size is bigger or smaller then the logicaldisk FreeSapce.
if it is true then put the files in.
if it flase, compare to next Drive
if all drives are not suitable, return a result.

here is the script.

$LogicalDrive=Get-CimInstance -Class CIM_LogicalDisk  |Where-Object {$_.DeviceID -ne "c:"}  |Sort-Object DeviceID
$isfolder=(Get-Item -Path $path).Mode

if($isfolder -eq "d-----"){
    $size = (Get-ChildItem -Path $path -Force -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
        "It is a floder and the size is $size"
        $size=(Get-Item -Path $path).Length
        "It is a file and the size is $size"

for($i=0;$i -lt $DiskNumber;$i++){
        if($size -le $LogicalDrive[$i].FreeSpace){
            Copy-Item -Path $path -Destination $DrivePath -Force
        Write-Host "Copy Item successfully"
        Write-Host "All Drive is full, no thing copied"

@Elio Welcome to forums.

AFAIK, Yes pretty much doable. to help folks here, can you share the code you have ? make sure you remove a sensitive data in code with samples.