Other posts found in this series
Another cool tool in the SysInternals suite is MoveFile and PendMoves. Rather than moving the file immediately the tool is used to move, rename or delete a file on restart. The System Manager looks at a special registry key to determine which files to are candidates to be operated on. I’ve created two cmdlets that mimic the function of the MoveFile tool. They both call the Win32 function MoveFileEx.
Move-FileOnReboot will (amazingly!) register a file to be moved on reboot.
Remove-FileOnReboot will do the same, except it will delete the file.
Get-PendingFileRenameOperation will return the files that are registered to be moved, renamed or delete.