I looked at this script, and it will always return "Operating system is not supported" because in the script $major and $minor are strings, I was able to confirm that with the commands: 
	 
	$major.GetType()
 
	IsPublic IsSerial Name                                     BaseType 
	-------- -------- ----                                     -------- 
	True     True     String                                   System.Object
 
	 
 
	$minor.GetType()
 
	IsPublic IsSerial Name                                     BaseType 
	-------- -------- ----                                     -------- 
	True     True     String                                   System.Object
 
	 
 
	I recommend updating the script to this, and I highlighted the changes:
 
	$version = (Get-WmiObject Win32_OperatingSystem).Version 
	[int]$major = $version.split(".")[0] 
	[int]$minor = $version.split(".")[1] 
	if ($major -gt 6 -or ($major -eq 6 -and $minor -gt 1)) { 
	    Optimize-Volume -driveletter $pwd.drive.name -Analyze -verbos 
	} Else { 
	    Write-Output "Operating system is not supported." 
	}
 
	 
 
	Here is the original script:
 
	$version = (Get-WmiObject Win32_OperatingSystem).Version 
	$major = $version.split(".")[0] 
	$minor = $version.split(".")[1] 
	if ($major -gt 6 -or ($major -eq 6 -and $minor -gt 1)) { 
	    Optimize-Volume $pwd.drive.name -Analyze -verbos 
	} Else { 
	    Write-Output "Operating system is not supported." 
	}
 
	 
 
	REF: https://learn.microsoft.com/en-us/powershell/module/storage/optimize-volume?view=windowsserver2022-ps
 
	REF: https://lazyadmin.nl/powershell/if-else-statements/
 
	REF: https://theitbros.com/powershell-convert-string-to-int/