There should not be a need for using a temp file for this request. Everything can be done in memory.
$HotFixes = Get-HotFix
if($HotFixes) { //True if there are results [not empty]
($HotFixes | Sort-Object -Property InstalledOn -Desc)[0].InstalledOn
}
This will return a long datatime formatted string. If you prefer a short date you can wrap the ($HotFixes line in another set of parenthesis and add .ToShortDateString()
He just showed you how to pull the latest date without a file. Did you even try his suggestion? My advice to you is stop treating powershell like text. Powershell works with objects. You keep turning it into text and outputting it vs extracting the info you desire from the rich objects at your disposal
PowerShell is object oriented as is the code I suggested. You can call that code without a batch script if I am understanding you correctly. Also it’s returning the date, so unsure why it needs to be stored as an exit code which is an integer value only
My explanation was “a little bit wrong”: The calling batch needs the difference in days between two dates (which is an integer).
Why calling PS from batch: I have a batch based system grown in 20 years and try to switch step by step to Powershell. Doing this in ne big step is not possible due to my capacities.