$SNMP = new-object -ComObject olePrn.OleSNMP
$NET = '10.2.2.'
$IP_all = @()
1..254 | %{ $IP_all += ($NET+$_) }
$udpobject = new-Object system.Net.Sockets.Udpclient
$udpobject.client.ReceiveTimeout = 1000
$a = new-object system.text.asciiencoding
$kk = @(48,36,2,1,1,4,6,112,117,98,108,105,99,161,23,2,2,117,6,2,1,0,2,1,0,48,11,48,9,6,5,43,6,1,2,1,5,0) # magic packet
foreach($IP in $IP_all)
{
if(!(Test-Connection -CN $IP -Count 1 -BufferSize 16 -Quiet)) { continue }
$conn = $udpobject.Connect($IP,161)
$ans = [void]$udpobject.Send($kk,$kk.length)
$remoteendpoint = New-Object system.net.ipendpoint([system.net.ipaddress]::Any,0)
$receivebytes = $udpobject.Receive([ref]$remoteendpoint)
[string]$returndata = $a.GetString($receivebytes)
$snmp.open($IP,'public',1,500)
$IP
$snmp.Get(".1.3.6.1.2.1.25.3.2.1.3.1") # ОИД Device Description - стандарт.
$snmp.Get(".1.3.6.1.2.1.1.5.0") # ОИД System Name - стандарт.
$snmp.Get(".1.3.6.1.2.1.43.5.1.1.17.1").Trim() # ОИД серийника - не стандарт!
"-------------------------------------------------------------------------------------"
}
$SNMP.Close()
#########################################################################################
##
## Скрипт для сбора данных по 1 ПК. Оформляем как функцию (или направляем в конвейер), если надо для списка ПК.
##
#########################################################################################
$StrComputer = $env:COMPUTERNAME # --- меняем на требуемый ПК, сейчас берет локальный.
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet1 = $Excel.Worksheets.Item(1)
$Sheet1.Name = "Inventory"
$Sheet1.Cells.Item(1,1) = "Имя"
$Sheet1.Cells.Item(1,2) = "Модель ПК"
$Sheet1.Cells.Item(1,4) = "Тип"
$Sheet1.Cells.Item(1,5) = "ЦПУ"
$Sheet1.Cells.Item(1,8) = "ОЗУ,GB"
$Sheet1.Cells.Item(1,6) = "Оп.система"
$Sheet1.Cells.Item(1,7) = "SP ОС"
$Sheet1.Cells.Item(1,3) = "Серийный №"
$Sheet1.Cells.Item(1,9) = "Диск(реал.),GB"
$Sheet1.Cells.Item(1,10) = "Диск(произ.),GB"
$colSheets = ($Sheet1)
foreach ($colorItem in $colSheets){
$WorkBook = $colorItem.UsedRange
$WorkBook.Interior.ColorIndex = 20
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True
}
#====================================================================================================
$intRow = 2
if ((Test-connection $StrComputer -count 2 -quiet) -eq "True")
{
$GenItems1 = gwmi Win32_ComputerSystem -Comp $StrComputer
$GenItems2 = gwmi Win32_OperatingSystem -Comp $StrComputer
$CPUItems = gwmi Win32_Processor -Comp $StrComputer
$SysItems1 = gwmi Win32_BIOS -Comp $StrComputer
$ProcItems1 = gwmi Win32_Processor -Comp $StrComputer
$DiskItems = gwmi Win32_LogicalDisk -Comp $StrComputer
$PhisDisk = gwmi Win32_DiskDrive -Comp $StrComputer
foreach ($objItem in $GenItems1)
{ $Sheet1.Cells.Item($intRow, 1) = $StrComputer
$Sheet1.Cells.Item($intRow, 2) = $objItem.Model
$Sheet1.Cells.Item($intRow, 4) = ($objItem.SystemType -replace "-based PC","")
$Sheet1.Cells.Item($intRow, 8) = [math]::Round(($objItem.TotalPhysicalMemory / 1024 / 1024 / 1024),2)
}
$Sheet1.Cells.Item($intRow, 5) = $CPUItems.Name
foreach ($objItem in $GenItems2)
{ $aa = ($objItem.Caption -replace "Microsoft Windows","MS Win")
$aa = ($aa -replace "Профессиональная","Проф.")
$aa = ($aa -replace "Professional","Проф.")
$aa = ($aa -replace "Корпоративная","Корп.")
$aa = ($aa -replace "Майкрософт Windows","MS Win")
$aa = ($aa -replace "(Registered Trademark)","")
$Sheet1.Cells.Item($intRow, 6) = $aa
$Sheet1.Cells.Item($intRow, 7) = ($objItem.csdversion -replace "Service Pack","SP")
}
foreach ($objItem in $SysItems1)
{
if( $objItem.SerialNumber -eq "System Serial Number") {$Sheet1.Cells.Item($intRow, 3) = "Самосборка"} else {$Sheet1.Cells.Item($intRow, 3) = $objItem.SerialNumber}
if( $objItem.SerialNumber -match "Parallels*" -or $objItem.SerialNumber -match "VMware*") {$Sheet1.Cells.Item($intRow, 3) = "VM"}
}
foreach ($objItem in $PhisDisk)
{
if( $objItem.Model -notmatch 'usb' )
{
$Sheet1.Cells.Item($intRow, 9) = [math]::Round(($objItem.Size/1024/1024/1024),2)
$Sheet1.Cells.Item($intRow, 10) = [math]::Round(($objItem.Size/1000/1000/1000),0)
}
}
$intRow += 1
}
else {" IP = "+$StrComputer + "--- не доступен."}
#====================================================================================================
foreach ($colorItem in $colSheets)
{
$WorkBook = $colorItem.UsedRange
$WorkBook.EntireColumn.AutoFit()
}