Forum Discussion
OneDrive with FSlogix in an AVD environment how to prevent profile bloat
It’s a bit ridiculous that people are having to invent their own solutions for this issue when it should just be part of a onedrive policy
I am in a similar situation, but it's exacerbated by the fact that we have a very aggressive deallocation automation setup to deallocate after 2-3hrs idle.
- steveturnbull1975May 18, 2023Brass Contributor
I just created it myself it’s set to run as “users” in the scheduled task security options so it’ll run as user context for any user who logs in. The trigger is set as “at log on” and “at logon of any user” with a delay task set as 30 minutes.
The action runs a vbs file
C:\windows\system32\wscript.exe “c:\profiles\onedrivecleanup.vbs”
It’s a vbs file as I wanted to hide the powershell pop-up at logon
Contents of vbs file is
Command = "powershell -nologo -command c:\profiles\onedrivecleanup.ps1”
Set shell =createobject(“WScript.Shell”)
shell.run command,0
then the powershell file contains the following
Get-childitem $env:userprofile’\onedrive - youronedrivecompanynameprobably’ -force -file -recurse |where-object {$_.lastwritetime -lt (get-date).adddays(-30)} |where attributes -eq ‘archive, reparsepoint’ | foreach { attrib.exe $_.fullname +U -P /s }
Obviously replace the oneddiveyourcompanyname with whatever onedrive folder you are interesting it scanningif you run the above in a test environment you should find for any files which haven't been modified in 30 days, it will set them back from a green tick to a blue cloud icon which means they have been removed from the container and back to online only mode.
- callen1485May 25, 2023Copper Contributor
Would it make sense to use lastAccessTime instead of lastwritetime?
lastwritetime doesn't doesn't change for image and video files unless they get modified. What happens if the user has an image file open that is older than 30 days when the script runs?