Hi everyone, I'm trying to make a script to recognize cpu, hdd/ssd and amount of ram...I have a problem with the RAM code, as it behaves differently on different PCs and I don't know how to solve it Can anyone help me? I have attached the script and the photo where the RAM problem is located
Try changing the parts to the green color ie remove the quotes around the values, there is a glitch in batch that not seem to like comparing numeric values when enclosed. As you have already done a precheck for the totalMemoryGB for being non defined then that will hopefully prevent a crash/error. Code: if not defined totalMemoryGB ( powershell -Command "Write-Host 'Non trovo la RAM' -ForegroundColor Red; exit" && timeout /t 4 >nul ) else ( if %totalMemoryGB% LEQ 3 ( set "ram=-" powershell -Command "Write-Host 'RAM insufficiente per i nuovi SO Win10/11, requisito minimo 4gb' -ForegroundColor Red; exit" && timeout /t 4 >nul ) else if %totalMemoryGB% EQU 4 ( set "ram=+" powershell -Command "Write-Host 'RAM minima per i nuovi SO Win10/11, espandila se possibile' -ForegroundColor DarkYellow; exit" && timeout /t 4 >nul ) else if %totalMemoryGB% GEQ 5 ( set "ram=ok" powershell -Command "Write-Host 'RAM sufficiente per i nuovi SO Win10/11 ' -ForegroundColor Green; exit" && timeout /t 4 >nul ) )
Its something that the command processor seems to get confused about. I fell foul to that string/numeric comparison in my early days of batch programming. The variable needs to be checked for non defined or set as 0 otherwise the batch script will crash if the variable is unset.
thx u so much, last question, is there a way to extract the processor number piece? I attach the photo, in my case I would like it to set for example the value numberCPU:6200 or 6gen
As the processor string is not consistent i not sure if that possible without a lot of if checks and a database of all cpus intel/amd. I have tried to get that information in my project but failed many times as my databases are always out of date so i gave up. Same with motherboard chipset versions and cpu socket types, m$ not seem to keep their internal data bases up to date.
enjoy the reading. https://learn.microsoft.com/en-us/p...about_regular_expressions?view=powershell-7.4 you can test your regex here https://regex101.com/ make sure to choose
with quotes, it's compared as strings bit by bit, so 1 is smaller than 9 Code: if "16" GTR "9" echo yes if 16 GTR 9 echo yes
Is there a reason why you keep calling PS one-liners from a CMD batch? Why not write a single PS script? View attachment 66498