1 at the wery beggining you could remove your file, so at the end you will get new one created
2 take a look on convertto-html cmdlet instead of using your foreach {"$_</br>> construction
3 line 7 doing nothing
4 instead of writing/reading file you can just use variable to store your results. In this case you will not be needed remove anything
$userlist =@()
Foreach ( $user_dir in ( Get-ChildItem "C:\Users" )) {
$Profile_Size = (Get-ChildItem -Recurse -Force -ea silentlycontinue -Path "$($user_dir.FullName)" | Measure-Object length -sum).sum
$sizemb = $Profile_Size / 1MB
$sizemb = [math]::round($sizemb,2)
if ($sizemb -gt 500) {
$userlist += [pscustomobject]@{
ProfileName = $user_dir.Name
ProfileSizeMB = $sizemb
}
}
}
$body = $userlist | ConvertTo-Html # more info you can find in a help and in attached link
https://4sysops.com/archives/building-html-reports-in-powershell-with-convertto-html/