Files
Powershell/get-serial.bat
T

40 lines
1.1 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
echo Retrieving laptop serial number...
:: Gebruik de huidige map als uitvoerlocatie
set "output_dir=%~dp0"
:: Verwijder de backslash aan het einde
set "output_dir=!output_dir:~0,-1!"
echo Uitvoerlocatie: !output_dir!
:: Get the serial number using PowerShell instead of WMIC
for /f "delims=" %%a in ('powershell -command "(Get-WmiObject -Class Win32_BIOS).SerialNumber"') do (
set "serial=%%a"
)
:: Remove any spaces from the serial number
set "serial=!serial: =!"
:: Check if serial number was found
if "!serial!"=="" (
echo Error: Could not retrieve serial number.
exit /b 1
)
:: Get the hostname
set "hostname=%COMPUTERNAME%"
:: Create a text file with HOSTNAME_SERIAL as the filename
set "filename=!hostname!_!serial!.txt"
echo Serial Number: !serial! > "!output_dir!\!filename!"
echo Computer Name: !hostname! >> "!output_dir!\!filename!"
echo Date: %DATE% >> "!output_dir!\!filename!"
echo Time: %TIME% >> "!output_dir!\!filename!"
echo Serial number !serial! has been saved to !output_dir!\!filename!
echo.
echo Script completed successfully.
pause
endlocal