PowerShell: Plug and Play seadmete kontrollimise skript

From ICO wiki
Jump to navigationJump to search
<Source lang="powershell">
<#
  .SYNOPSIS
     Sckipt trükib välja lühikene arvuti info ja kontrollib "Plug and Play" seaded, kas seal on mingeid vead.
     Kui kõik on OK, siis script teavitab et kõik on korras, aga kui ta leiab mingeid seadme probleemid,
     siis ta trükib välja infot selle seadmete kohta ja kirjeldab, mis probleem teil on.
  .DESCRIPTION
     Sckipt käivitab parameetrita
  .EXAMPLE
     C:\PS>.\brokenHardware.ps1
  .NOTES
     Autor: Jevgeni Pogodin
     Versioon: 0.1 
     Muutmise kuup2ev: 29.04.2012
  .LINK
     https://wiki.itcollege.ee/index.php/PowerShell:_Plug_and_Play_seadmete_kontrollimise_skript
#>
#Näitab arvuti infot 
Write-Host "Arvuti andmeid:" -BackgroundColor Yellow -ForegroundColor Black
$comp = Get-WmiObject Win32_ComputerSystem 
    Write-Host "Tootja: "        $comp.Manufacturer 
    Write-Host "Mudel:  "        $comp.Model
$comp2 = Get-WmiObject Win32_ComputerSystemProduct 
    Write-Host "Service Tag: "   $comp2.IdentifyingNumber
    Write-Host "Arvuti nimi: "   $comp.Name
    Write-Host "Süsteemi tüüp: " $comp.SystemType
    Write-Host "Omanik: "        $comp.PrimaryOwnerName
    Write-Host "Mälu: "          ([math]::truncate($comp.TotalPhysicalMemory/1MB))
    Write-Host #Lihtsalt tühi rida
#Saab  kätte "Plug and Play" arvuti seaded, kus on vead
$broken = Get-WmiObject Win32_PnPEntity | where {$_.ConfigManagerErrorCode -ne 0}

#Kui vead on, trükkib välja veade infot
if($broken){
    Write-Host "Seade nimikiri, kus leiakse probleemid" -Background Red -ForegroundColor Black
    Write-Host "_______________________"
    #Näitab seade vead 
    foreach ($obj in $broken){   
       Write-Host "Description: " $obj.Description
       Write-Host "Name:        " $obj.Name
       Write-Host "Device ID:   " $obj.DeviceID 
       Write-Host "Error ID:    " $obj.ConfigManagerErrorCode
       Write-Host "Hardware ID: " $obj.HardwareID
       Write-Host "Service:     " $obj.Service
       if($obj.ConfigManagerErrorCode -eq 1){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seade ei ole korrektselt seadistatud" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 2){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Windows ei saa laadida draiverit selle seadmete" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 3){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Draiver selle seadme jaoks võib olla vigastatud, või süsteem võib olla vähe mälu või muud ressursid" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 4){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seade ei tööta korralikult. Üks selle draiverite või registrite võib olla vigastatud" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 5){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Draiveri seade vajab ressurssi, mis Windows ei suuda" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 6){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Käivitu konfiguratsiooni seade konflikte teiste seadmetega" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 7){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Ei saa filtreerida" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 8){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Draiveri laaduri seade puudub" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 9){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seade ei tööta korralikult. Kontrolliva püsivara on valesti aru ressursside seadet" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 10){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seade ei saa käivitada" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 11){
           Write-Host "Error Discription: " $obj.ErrorDescription = "seadet ei ole" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 12){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seade ei leia piisavalt vaba ressursside kasutamiseks" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 13){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Windows ei saa kontrollida seadme ressursse" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 14){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seade ei saa korralikult töötada, kuni arvuti taaskäivitatakse" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 15){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seade ei tööta korralikult kuna võimalik uuesti loendamise probleeme" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 16){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Windows ei suuda identifitseerida kõiki ressursse, mis kasutab seade" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 17){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seade taotleb teadmata ressurssi tüüp" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 18){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seadmete draiverid tuleb uuesti installeerida" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 19 ){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Failure using the VxD loader" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 20){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Registri võiks olla vigastatud" -Background Green -ForegroundColor Black
       }
       elseif(($obj.ConfigManagerErrorCode -eq 21) -or ($obj.ConfigManagerErrorCode -eq 23)){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Süsteemi rike" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 22){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seade on välja lülitatud" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 24){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seadet ei ole, ei tööta korralikult või puudub kõigi oma installitud draivereid" -Background Green -ForegroundColor Black
       }
       elseif(($obj.ConfigManagerErrorCode -eq 25) -or ($obj.ConfigManagerErrorCode -eq 26)){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Windows on veel luuakse seadet" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 27){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seadmel puudub kehtiv logi konfiguratsioon" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 28){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seade draiverid on installimata" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 29){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seade on välja lülitatud. Seadme firmware ei esitanud vajalike ressursside" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 30){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Device is using an IRQ resource that another device is using" -Background Green -ForegroundColor Black
       }
       elseif($obj.ConfigManagerErrorCode -eq 31){
           Write-Host "Error Discription: " $obj.ErrorDescription = "Seade ei tööta korralikult. Windows ei saa laadida vajaliku seadme draiverid" -Background Green -ForegroundColor Black
       }
       Write-Host #Lihtsalt tühi rida
   }
}
#Kui vead ei ole, siis ütleb, et teie masin töötab õigesti
else{
  Write-Host "Sckipt ei leia vead. Teie seadeid töötavad korralikult!!!!" -Background Green -ForegroundColor Black
}