Script to collect ost file sizes from a list of computers over 18GB and email

$ComputersPath = “c:\scripts\folderlist.txt”

$SmtpServer = “”
$SmtpPort =
$to = “”
$from = “”
$sub = “”
$body = @()

$body =
ForEach ($Computer in (Get-Content $ComputersPath))
{ If ($Computer)
{ ForEach ($Drive in “C”,“D”)
{ If (Test-Path “\$Computer$($Drive)`$” -ErrorAction Stop)
{ $Log += ForEach ($OST in ($OSTS = Get-ChildItem “\$Computer$($Drive)`$” -Include *.ost -Recurse -Force -erroraction silentlycontinue))
{ New-Object PSObject -Property @{
ComputerName = $Computer
Path = $OST.DirectoryName
FileName = $OST.BaseName
Size = “{0:N2} GB” -f ($OST.Length / 18gb)
}
}
}
}
}
}

Send-MailMessage -SmtpServer $SmtpServer -Port $SmtpPort -To $to -Subject $sub -Body ($body | ConvertTo-Html -Head $head | Out-String) -From $from -BodyAsHtml

What problem are you facing, are you getting any errors ? please read below post and forma the code based on the instructions.

https://powershell.org/forums/topic/read-me-before-posting-youll-be-glad-you-did/

This is the error I am getting below, could it be to do with the path being incorrectly added?

Get-ChildItem : The network path was not found
At line:15 char:37

  • … in ($OSTS = Get-ChildItem “\$Computer$($Drive)`$” -Include *.ost - …
  • CategoryInfo : NotSpecified: (:slight_smile: [Get-ChildItem], IOException
  • FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.GetChildI
    temCommand

Print “\$Computer$($Drive)`$” and see whats there in it. Check if its a valid path or not.