Good morning Everyone,
I was hoping to find a topic on this, but I have had no luck.
My end goal is to delete *.OST files within the user profiles on shared computers.
I have a powershell script that works. I was hoping to either integrate it into a FixLet or create a FixLet to complete the task.
Here is the powershell I have ran with success:
Set-ExecutionPolicy Unrestricted
$users = Get-ChildItem c:\users
foreach ($user in $users){
$folder = “C:\users” + $user +"\AppData\Local\Microsoft\Outlook"
$folderpath = test-path -Path $folder
if($folderpath)
{
Get-ChildItem $folder -filter *.ost | where-object {($_.LastWriteTime -lt (Get-Date).Addminutes(-1))} | remove-item
Write-Output “Deleted OST file for $user”
}
else{
Write-Output “OST file doesn’t exist or meet criteria for $user”
}
}
I am sure this can be cleaned up some or made more simple.
I have attempted to use the template that @jgstew has posted. https://bigfix.me/fixlet/details/3860
Thank you for the input
1 Like
Looks like your curly braces are getting parsed as Relevance Substitution. Is your powershell,try escaping the opening {
with {{
https://developer.bigfix.com/action-script/guide/substitution.html
2 Likes
@brolly33
Thanks for the information. To understand the placement of the {{
Will I place it here foreach ($user in $users){{ or place the double {{ in the very beginning?
Sorry for the green horn questions.
1 Like
A little more explanation at Tip: Escaping curly brackets for substitutions in ActionScript , but you need to replace every {
with {{
if you do not want any relevance substitutions.
2 Likes
I will update it and give it a try.
Thanks
As a secondary option
@echo off
for /f "delims=|" %%f in ('dir /B /A:D-H-R c:\users') do (DEL "C:\Users\%%f\AppData\Local\Microsoft\Outlook\*.ost" /S /Q)
@MMosley you are giving me .BAT file flashbacks with that.
Confession: I once wrote a software distribution that used nothing but .BAT files with for loops and psexec (before I found BigFix)
Man… the good ole days. I used to have a script for everything, usually also using psexec lol. It definitely made life easier in most cases.