How to divide a folder with over a million files into smaller folders

I have a shared folder with over a million files into it, is there a way to split the contents into many smaller folders ?

You might try New-Item to create additional directories to split/move the items into, and then use Move-Item to move certain items to the folders/subfolders you create. With a million files, you’ll probably want to use the -Filter parameter, of the Move-Item cmdlet, to get a subset of the files that you want to move to a particular folder.

You can use the same -Filter parameter on Get-Item, storing the results into a variable, and then dumping out the variable to make sure you will be moving the items you want to move to a particular folder/subfolder. You can then pipe the variable to the Move-Item cmdlet.

I would think using a variable may use a lot of memory, try piping from the get-item directly to the move-item, it should be more memory efficient.

That’s definitely possible, but before running a Get/Move script, with guns-a-blazing, on a million files it’s good to verify that the right set of objects will be affected by the Move-Item cmdlet. If the filter can be fine-tuned enough, for a test, that would be the best thing before running the code on the full set.