cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Green14
Level: Powered On

OneDrive for Business - Delete files in folder if they are more than 50

Hello,
 
I am currently using the following Powershell script:
dir "PATH" | ? {!$_.psiscontainer} | sort LastWriteTime -desc | select -skip(50) | del

The script makes sure that I keep the newest 50 files in one folder. As soon as there are more than 50 files, the oldest ones should be deleted.

 

How can I implement this in Microsoft Flow? Can I also use Powershell commands in Flow?

 

Thanks 

Green14

1 REPLY 1
v-zhos-msft
Level 10

Re: OneDrive for Business - Delete files in folder if they are more than 50

Hi @Green14 ,

It seems that you would like to keep the newest 50 files in one folder. And delete the older ones.

I am afraid that there is no way to achieve your needs in Microsoft Flow currently.

There is no function to sort the files by created time in the flow.

Here is a similar idea with your case, you can vote the idea here:

https://powerusers.microsoft.com/t5/Flow-Ideas/sort-onedrive-list-of-files-with-optional-delete/idi-...

Best Regards,

Community Support Team _ Zhongys

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (5,283)