technoolli
Goto Top

Remote SN von angeschlossenen Monitoren per PS auslesen

Ich habe eine Liste der PCs im Netzwerk per PS erstellen und zwar mit folgenden Befehl:

Get-ADComputer -Filter {enabled -eq $true} -Properties *|select Name, OperatingSystem, LastLogonDate | Export-Csv C:\ad_objects.csv -NoTypeInformation -Encoding UTF8 -Delimiter ";"  

Jetzt möchte Ich noch die Angeschlossenen Monitore (S/N) auslesen und mit auf die Liste bekommen, dieses gerne uch per PS auslesen und in die CSV Datei importieren.

Kann mir wer dabei helfen, jemand ne Idee wie man das realisieren könnte, meine Versuche haben nichts passenden ausgegeben.

Dankeschön.

Content-ID: 667845

Url: https://administrator.de/contentid/667845

Ausgedruckt am: 26.09.2024 um 23:09 Uhr

CamelCase
CamelCase 03.09.2024 aktualisiert um 13:20:40 Uhr
Goto Top
Auch kein Moin,

hier eine Funktion, die ich dafür verwende. Kombiniere das mit deinem Code, um mehrere PCs abzufragen:

function Get-MonitorInfo {
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
        [string[]]$ComputerName = $env:COMPUTERNAME
    )

    process {
        foreach ($Computer in $ComputerName) {
            try {
                $Monitors = Get-CimInstance -ClassName WmiMonitorID -Namespace root\wmi -ComputerName $Computer -ErrorAction Stop

                foreach ($Monitor in $Monitors) {
                    $Manufacturer = ($Monitor.ManufacturerName -notmatch 0 | ForEach-Object {[char]$_}) -join ""  
                    $Name = ($Monitor.UserFriendlyName -notmatch 0 | ForEach-Object {[char]$_}) -join ""  
                    $Serial = ($Monitor.SerialNumberID -notmatch 0 | ForEach-Object {[char]$_}) -join ""  

                    [PSCustomObject]@{
                        ComputerName = $Computer
                        Manufacturer = $Manufacturer
                        Name = $Name
                        SerialNumber = $Serial
                    }
                }
            }
            catch {
                Write-Error "Failed to retrieve monitor information from $Computer. Error: $_"  
            }
        }
    }
}
Technoolli
Technoolli 03.09.2024 aktualisiert um 13:08:24 Uhr
Goto Top
Womit kann ich den starten als batch cmd oder Powershell ps1 oder was ist das für ein Code sorry das ich frage habe gerade wegen der Hitze ein Brett vor dem Kopf *gggg*
CamelCase
CamelCase 03.09.2024 aktualisiert um 13:23:33 Uhr
Goto Top
Versuchs mal damit, als ps1 speichern und mit entsprechenden Rechten ausführen

function Get-MonitorInfo {
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
        [string[]]$ComputerName = $env:COMPUTERNAME
    )

    process {
        foreach ($Computer in $ComputerName) {
            try {
                $Monitors = Get-CimInstance -ClassName WmiMonitorID -Namespace root\wmi -ComputerName $Computer -ErrorAction Stop

                foreach ($Monitor in $Monitors) {
                    $Manufacturer = ($Monitor.ManufacturerName -notmatch 0 | ForEach-Object {[char]$_}) -join ""    
                    $Name = ($Monitor.UserFriendlyName -notmatch 0 | ForEach-Object {[char]$_}) -join ""    
                    $Serial = ($Monitor.SerialNumberID -notmatch 0 | ForEach-Object {[char]$_}) -join ""    

                    [PSCustomObject]@{
                        ComputerName = $Computer
                        Manufacturer = $Manufacturer
                        Name = $Name
                        SerialNumber = $Serial
                    }
                }
            }
            catch {
                Write-Error "Failed to retrieve monitor information from $Computer. Error: $_"    
            }
        }
    }
}
$MonitorInfo = @()
(Get-ADComputer -Filter {enabled -eq $true}).name | ForEach-Object {
    If (Test-Connection $_ -Count 1 -Quiet) {
        $MonitorInfo += Get-MonitorInfo -ComputerName $_
    } else {
        Write-Output "$_ ist nicht online"  
    }

}

$MonitorInfo | Export-Csv C:\monitor-serials.csv -NoTypeInformation -Encoding UTF8 -Delimiter ";"