Hi. Sorry for my English - Im languagecripple.
I found nice script to take monitor serial. I need put serial and monitor model to txt file and after that read it by batch. But it doesnt work and i dont know why. I suppose that problem is in convert from ASCII code to char. Maybe first i show my batch code:
@echo off
SETLOCAL EnableDelayedExpansion
FOR /F "usebackq" %%v IN (`powershell -noprofile -executionpolicy bypass -File "mon.ps1"`) DO set "monitor=%%v"
echo here is first tray with monitor variable: %monitor%
echo.
FOR /F "tokens=*" %%v IN (serial.txt) DO set "monitor=%%v"
echo here is second tray with monitor variable: %monitor%
echo.
pause>nul
Now i show mon.ps1. First tray with simpler version:
$Monitory = gwmi -Namespace root\wmi -Class wmiMonitorID
foreach ($Monitor in $Monitory)
{
$serial = $null
$Monitor.SerialNumberID | foreach {$serial += [char]$_}
if ($serial -ne 0)
{
Remove-Item serial.txt
[System.IO.File]::AppendAllText("serial.txt", $serial, [System.Text.Encoding]::Unicode)
}
}
This code creates serial.txt with serial from my monitor, but batch doesnt show it. A little change and... batch show serial correct:
$Monitory = gwmi -Namespace root\wmi -Class wmiMonitorID
foreach ($Monitor in $Monitory)
{
$serial = $null
$Monitor.SerialNumberID | foreach {$serial += [char]$_}
$serial
if ($serial -ne 0)
{
Remove-Item serial.txt
[System.IO.File]::AppendAllText("serial.txt", $serial, [System.Text.Encoding]::Unicode)
}
}
I dont know why when i put $serial, the output txt is different and batch see this serial. But i need serial and name:
$Monitory = gwmi -Namespace root\wmi -Class wmiMonitorID
$MonitorDetal = @()
foreach ($Monitor in $Monitory)
{
$MonitorTemp = New-Object PSObject
$serial = $null
$name = $null
$Monitor.SerialNumberID | foreach {$serial += [char]$_}
$Monitor.UserFriendlyName | foreach {$name += [char]$_}
if ($serial -ne 0)
{
$MonitorTemp = $serial
$MonitorTemp += $name
$MonitorDetal += $MonitorTemp
}
else
{
$MonitorTemp = "empty "
$MonitorTemp += "empty"
$MonitorDetal += $MonitorTemp
}
}
Remove-Item serial.txt
[System.IO.File]::AppendAllText("serial.txt", $MonitorDetal, [System.Text.Encoding]::Unicode)What should I do with this?