This worked on the built-in Windows PowerShell to get the recommendation status:
$volume = Get-WmiObject -Class Win32_Volume -Filter "DriveLetter = 'C:'"
$analysis = $volume.DefragAnalysis()
$analysis.DefragAnalysis
$analysis.DefragRecommended
Without elevation token, $analysis.DefragAnalysis will be empty and $analysis.DefragRecommended will return False, but elevated it will return the analysis data and $analysis.DefragRecommended will return False or True depending on the analysis result.,
And this gets the most recent defragmentation action from the event-log:





