Blog
Hier poste ich dinge zu Themen die mich beschäftigten.
Suchen
2024-03-04
Angeschlossene Monitore auslesen
function Get-MonitorInfo {
$MonitorInfo = Get-WmiObject WmiMonitorID -Namespace rootwmi -ComputerName $env:COMPUTERNAME
$Output = @()
$SeenSerials = @()
foreach ($Monitor in $MonitorInfo) {
$Serial = ($Monitor.SerialNumberID -notmatch ‘^0$’ | ForEach-Object {[char]$_}) -join “”
if ($SeenSerials -contains $Serial) {
continue
}
$SeenSerials += $Serial
$Manufacturer = ($Monitor.ManufacturerName -notmatch ‘^0$’ | ForEach-Object {[char]$_}) -join “”
$Name = ($Monitor.UserFriendlyName -notmatch ‘^0$’ | ForEach-Object {[char]$_}) -join “”
$Output += “Manufacturer: $Manufacturer`nName: $Name`nSerial: $Serial`n”
}
return $Output
}
# Überprüfen des IP-Bereichs vor der Ausführung
$CurrentIP = (Get-NetIPAddress -AddressFamily IPv4).IPAddress
$AllowedIPRange = “192.168.200.*” # Beispiel-IP-Bereich, anpassen nach Bedarf
if ($CurrentIP -like $AllowedIPRange) {
cls
$MonitorInfo = Get-MonitorInfo
# Definieren des Freigabepfads und Erstellen des Dateinamens
$SharedPath = “c:tmp” # Anpassen an Ihren Freigabepfad
$Date = Get-Date -Format “yyyyMMdd”
$FileName = “MonitorInfo_$Date” + “_” + $env:COMPUTERNAME + “.txt”
$FullFilePath = Join-Path -Path $SharedPath -ChildPath $FileName
# Schreiben der Informationen in die Datei im Freigabepfad
$MonitorInfo | Out-File -FilePath $FullFilePath
# Optionale Ausgabe zur Bestätigung
Write-Host “Monitor information saved to $FullFilePath”
} else {
Write-Host “This script is not allowed to run in the current IP range.”
}
Admin - 16:29:45 @ Projekte, Powershell-Skripte | Kommentar hinzufügen
Kommentar hinzufügen
Die Felder Name und Kommentar sind Pflichtfelder.