How to send the output of this script to a file that resembles a log file of sorts

Hi guys, simple one here.

This script looks through user profiles located in a folder.

It looks at a file within each user’s user folder and clears it if it’s too large (this is to prevent bloated user profiles).

After it checks the file, it returns either “The operation completed successful” indicated by the (Reg unload HKULOADED) line. Or if there is stuff to delete, it returns “Ready to delete” indicated by (Write-Host “ready to delete”).

My question is:

  • With “Out-file” or whatever cmdlet works, how do I output the results of the User account file test? I would like to have a log file of sorts that logs whether the account scan was “completed successfully” or if it needed to delete the file contents “ready to delete”.

I’m after something like this:


(User account) (Whether it was successful or not)

(User account (Whether it was successful or not)


Just a basic log file.

Where in my code would I put the cmdlet? I’m not too good at this.

Thanks 🙂


write-host "Starting check" $userlist = ls "C:UsersAntonDesktopTest EnvironmentsCitrix Bloated ProfileAccounts" foreach ($user in $userlist){ $username = $user.name Write-Host "Processing - $username" $hivePath = "C:UsersAntonDesktopTest EnvironmentsCitrix Bloated ProfileAccounts$usernameprofileUPM_ProfileNTUSER.DAT" Reg Load HKULOADED $hivePath | Out-Null $Drive = New-PSDrive -Name HKUDEFAULT -PSProvider Registry -Root HKEY_USERS -Scope Script New-Variable -Name DriveName -Value ($Drive.Name) $Root = $DriveName + ":Loaded" if (Test-Path "$RootSoftwareRICOH") { Write-Host "ready to delete" Remove-Item "$RootSoftwareRICOH" -Recurse -Force } [gc]::collect() Get-PSDrive $DriveName | Remove-PSDrive -Force remove-variable -Name DriveName -Force [gc]::collect() Reg unload HKULOADED } write-host "Finished" 

submitted by /u/OrangeMaterial
[link] [comments]

Leave a Reply