Need to export laptop specs to my usb
Hi all
So I created an iso image with ADK to run my info.bat
Now I have encountered a new problem I need to export the info.txt file that contains the computer information on my usb.
2. And it will be better if I can loop the “CD” commands and execute directly info.bat without having to write all these commands at startup
info.bat
wpeinit
@echo off
setlocal enabledelayedexpansion
set ScriptName=bat.ps1
set USBDrivePath=X:WindowsSystem32Apps
echo Checking for the script in %USBDrivePath%…
rem Check if the specified path exists
if exist “%USBDrivePath%%ScriptName%” (
echo USB drive found at %USBDrivePath%.
echo Executing script: %USBDrivePath%%ScriptName%
powershell -ExecutionPolicy Bypass -File “%USBDrivePath%%ScriptName%”
) else (
echo USB drive not found or script not present.
pause
)
endlocal
bat.ps1 :
# Set the path for the USB drive
$usbDrivePath = “X:WindowsSystem32Apps”
# Gather system information
$namespace = “ROOTcimv2”
# Battery Information
$battery = Get-CimInstance -Namespace $namespace -ClassName “Win32_Battery”
$namespace = “ROOTWMI”
$FullChargedCapacity = (Get-CimInstance -Namespace $namespace -ClassName “BatteryFullChargedCapacity”).FullChargedCapacity
$DesignedCapacity = (Get-WmiObject -Namespace $namespace -ClassName “BatteryStaticData”).DesignedCapacity
$batteryInfo = “No battery information available.”
if ($battery) {
$batteryInfo = @”
$([math]::Round(($FullChargedCapacity / $DesignedCapacity) * 100)) %
“@
}
# Device Info
$ComputerModel = (Get-WmiObject -Class:Win32_ComputerSystem).Model
# CPU Information
$cpu = Get-CimInstance -ClassName Win32_Processor
$cpuName = $cpu.Name
# GPU Information
$gpu = Get-CimInstance -Namespace rootcimv2 -ClassName Win32_VideoController
$gpuName = $gpu.Name -join “; ” # Join multiple GPUs if present
# Memory Information
$memory = Get-CimInstance -ClassName Win32_PhysicalMemory
$totalMemory = 0
foreach ($m in $memory) {
$totalMemory += $m.Capacity
}
$totalMemoryGB = [math]::Round($totalMemory / 1GB)
# Physical Disk Information
$diskInfo = “”
$primaryDisk = Get-CimInstance -ClassName Win32_DiskDrive | Where-Object { $_.Index -eq 0 }
if ($primaryDisk) {
$totalSizeGB = [math]::Round($primaryDisk.Size / 1GB, 2)
$diskInfo = “$totalSizeGB GB”
} else {
$diskInfo = “No primary disk found.”
}
# Prompt the user for BIOS information
$biosInfo = Read-Host “Please enter BIOS information”
# Display system information
Write-Host “————————————-“
Write-Host “Computer Model: $ComputerModel”
Write-Host “Battery Info: $batteryInfo”
Write-Host “CPU: $cpuName”
Write-Host “GPU: $gpuName”
Write-Host “Memory: $totalMemoryGB GB”
Write-Host “Disk: $diskInfo”
Write-Host “BIOS Information: $biosInfo”
Write-Host “————————————-“
# Set the path for the output text file
$txtFilePath = “${usbDrivePath}Info.txt” # Save to the USB drive
# Function to gather additional information
function Gather-Information {
$screenInfo = Read-Host “Please enter screen information”
$keyboardInfo = Read-Host “Please enter keyboard information”
$otherInfo = Read-Host “Please enter other information”
$priceInfo = Read-Host “Please enter price information”
return @{
Screen = $screenInfo
Keyboard = $keyboardInfo
Other = $otherInfo
Price = $priceInfo
}
}
# Function to export information to a text file with UTF-8 encoding
function Export-Information {
param (
[hashtable]$systemInfo,
[hashtable]$userInfo,
[int]$entryNumber # Accept the entry number
)
# Create a formatted string for output
$output = @”
Date: $(Get-Date)
Number: $entryNumber
Computer Model: $($systemInfo.ComputerModel)
Battery Info: $($systemInfo.BatteryInfo)
CPU: $($systemInfo.CPU)
GPU: $($systemInfo.GPU)
Memory: $($systemInfo.MemoryGB) GB
Disk: $($systemInfo.DiskInfo)
BIOS Information: $($systemInfo.BIOSInfo)
Screen: $($userInfo.Screen)
Keyboard: $($userInfo.Keyboard)
Other Information: $($userInfo.Other)
Price: $($userInfo.Price)
“@
# Append the information to the text file with UTF-8 encoding
$output | Out-File -FilePath $txtFilePath -Encoding UTF8 -Append
Write-Host “System information saved to $txtFilePath”
}
# Function to run the keyboard test utility
function Run-keytest {
$keyboardTestPath = “${usbDrivePath}keytest.exe”
if (-Not (Test-Path $keyboardTestPath)) {
Write-Host “keytest not found in $usbDrivePath.”
return $false
}
try {
Start-Process -FilePath $keyboardTestPath -Wait
return $true
} catch {
Write-Host “Failed to run keytest: $_”
return $false
}
}
# Function to eject the USB drive
function Eject-USB {
$ejectCommand = “powershell -command “”(New-Object -COMObject Shell.Application).Namespace(‘$usbDrivePath’).InvokeVerb(‘Eject’)”””
Start-Process -FilePath powershell -ArgumentList $ejectCommand -Wait
Write-Host “USB drive ‘$usbDrivePath’ ejected.”
}
# Main script execution
Write-Host “Starting keyboard test utility…”
# Prompt the user for the starting number
$startingNumber = Read-Host “Please enter the starting number”
if (-not [int]::TryParse($startingNumber, [ref]$null)) {
Write-Host “Invalid number entered. Please enter a valid integer.”
exit 1
}
if (Run-keytest) {
Write-Host “Keyboard test completed. Proceeding to enter additional information.”
# Gather system information into a hashtable
$systemInfo = @{
ComputerModel = $ComputerModel
BatteryInfo = $batteryInfo
CPU = $cpuName
GPU = $gpuName
MemoryGB = $totalMemoryGB
DiskInfo = $diskInfo
BIOSInfo = $biosInfo # Include user-entered BIOS information
}
# Call the function to gather additional information
$userInfo = Gather-Information
# Export everything to a text file with the user-defined starting number
Export-Information -systemInfo $systemInfo -userInfo $userInfo -entryNumber $startingNumber
# Eject the USB drive
Eject-USB
# Shutdown the PC
Stop-Computer -Force
} else {
Write-Host “Keyboard test was not completed successfully.”
}
Hi allSo I created an iso image with ADK to run my info.batNow I have encountered a new problem I need to export the info.txt file that contains the computer information on my usb.2. And it will be better if I can loop the “CD” commands and execute directly info.bat without having to write all these commands at startupinfo.bat wpeinit
@echo off
setlocal enabledelayedexpansion
set ScriptName=bat.ps1
set USBDrivePath=X:WindowsSystem32Apps
echo Checking for the script in %USBDrivePath%…
rem Check if the specified path exists
if exist “%USBDrivePath%%ScriptName%” (
echo USB drive found at %USBDrivePath%.
echo Executing script: %USBDrivePath%%ScriptName%
powershell -ExecutionPolicy Bypass -File “%USBDrivePath%%ScriptName%”
) else (
echo USB drive not found or script not present.
pause
)
endlocal bat.ps1 : # Set the path for the USB drive
$usbDrivePath = “X:WindowsSystem32Apps”
# Gather system information
$namespace = “ROOTcimv2”
# Battery Information
$battery = Get-CimInstance -Namespace $namespace -ClassName “Win32_Battery”
$namespace = “ROOTWMI”
$FullChargedCapacity = (Get-CimInstance -Namespace $namespace -ClassName “BatteryFullChargedCapacity”).FullChargedCapacity
$DesignedCapacity = (Get-WmiObject -Namespace $namespace -ClassName “BatteryStaticData”).DesignedCapacity
$batteryInfo = “No battery information available.”
if ($battery) {
$batteryInfo = @”
$([math]::Round(($FullChargedCapacity / $DesignedCapacity) * 100)) %
“@
}
# Device Info
$ComputerModel = (Get-WmiObject -Class:Win32_ComputerSystem).Model
# CPU Information
$cpu = Get-CimInstance -ClassName Win32_Processor
$cpuName = $cpu.Name
# GPU Information
$gpu = Get-CimInstance -Namespace rootcimv2 -ClassName Win32_VideoController
$gpuName = $gpu.Name -join “; ” # Join multiple GPUs if present
# Memory Information
$memory = Get-CimInstance -ClassName Win32_PhysicalMemory
$totalMemory = 0
foreach ($m in $memory) {
$totalMemory += $m.Capacity
}
$totalMemoryGB = [math]::Round($totalMemory / 1GB)
# Physical Disk Information
$diskInfo = “”
$primaryDisk = Get-CimInstance -ClassName Win32_DiskDrive | Where-Object { $_.Index -eq 0 }
if ($primaryDisk) {
$totalSizeGB = [math]::Round($primaryDisk.Size / 1GB, 2)
$diskInfo = “$totalSizeGB GB”
} else {
$diskInfo = “No primary disk found.”
}
# Prompt the user for BIOS information
$biosInfo = Read-Host “Please enter BIOS information”
# Display system information
Write-Host “————————————-“
Write-Host “Computer Model: $ComputerModel”
Write-Host “Battery Info: $batteryInfo”
Write-Host “CPU: $cpuName”
Write-Host “GPU: $gpuName”
Write-Host “Memory: $totalMemoryGB GB”
Write-Host “Disk: $diskInfo”
Write-Host “BIOS Information: $biosInfo”
Write-Host “————————————-“
# Set the path for the output text file
$txtFilePath = “${usbDrivePath}Info.txt” # Save to the USB drive
# Function to gather additional information
function Gather-Information {
$screenInfo = Read-Host “Please enter screen information”
$keyboardInfo = Read-Host “Please enter keyboard information”
$otherInfo = Read-Host “Please enter other information”
$priceInfo = Read-Host “Please enter price information”
return @{
Screen = $screenInfo
Keyboard = $keyboardInfo
Other = $otherInfo
Price = $priceInfo
}
}
# Function to export information to a text file with UTF-8 encoding
function Export-Information {
param (
[hashtable]$systemInfo,
[hashtable]$userInfo,
[int]$entryNumber # Accept the entry number
)
# Create a formatted string for output
$output = @”
Date: $(Get-Date)
Number: $entryNumber
Computer Model: $($systemInfo.ComputerModel)
Battery Info: $($systemInfo.BatteryInfo)
CPU: $($systemInfo.CPU)
GPU: $($systemInfo.GPU)
Memory: $($systemInfo.MemoryGB) GB
Disk: $($systemInfo.DiskInfo)
BIOS Information: $($systemInfo.BIOSInfo)
Screen: $($userInfo.Screen)
Keyboard: $($userInfo.Keyboard)
Other Information: $($userInfo.Other)
Price: $($userInfo.Price)
“@
# Append the information to the text file with UTF-8 encoding
$output | Out-File -FilePath $txtFilePath -Encoding UTF8 -Append
Write-Host “System information saved to $txtFilePath”
}
# Function to run the keyboard test utility
function Run-keytest {
$keyboardTestPath = “${usbDrivePath}keytest.exe”
if (-Not (Test-Path $keyboardTestPath)) {
Write-Host “keytest not found in $usbDrivePath.”
return $false
}
try {
Start-Process -FilePath $keyboardTestPath -Wait
return $true
} catch {
Write-Host “Failed to run keytest: $_”
return $false
}
}
# Function to eject the USB drive
function Eject-USB {
$ejectCommand = “powershell -command “”(New-Object -COMObject Shell.Application).Namespace(‘$usbDrivePath’).InvokeVerb(‘Eject’)”””
Start-Process -FilePath powershell -ArgumentList $ejectCommand -Wait
Write-Host “USB drive ‘$usbDrivePath’ ejected.”
}
# Main script execution
Write-Host “Starting keyboard test utility…”
# Prompt the user for the starting number
$startingNumber = Read-Host “Please enter the starting number”
if (-not [int]::TryParse($startingNumber, [ref]$null)) {
Write-Host “Invalid number entered. Please enter a valid integer.”
exit 1
}
if (Run-keytest) {
Write-Host “Keyboard test completed. Proceeding to enter additional information.”
# Gather system information into a hashtable
$systemInfo = @{
ComputerModel = $ComputerModel
BatteryInfo = $batteryInfo
CPU = $cpuName
GPU = $gpuName
MemoryGB = $totalMemoryGB
DiskInfo = $diskInfo
BIOSInfo = $biosInfo # Include user-entered BIOS information
}
# Call the function to gather additional information
$userInfo = Gather-Information
# Export everything to a text file with the user-defined starting number
Export-Information -systemInfo $systemInfo -userInfo $userInfo -entryNumber $startingNumber
# Eject the USB drive
Eject-USB
# Shutdown the PC
Stop-Computer -Force
} else {
Write-Host “Keyboard test was not completed successfully.”
} Read More