• Home
  • Склеротик
  • Ab me
  • galery
  • Home
  • Articles MicroSoft
  • AD inventory powershell
http://11dle.com
http://dle-shablons.ru
23 янв2020

AD inventory powershell

23 января 2020. Written by Super User. Posted in Articles MicroSoft

Import-Module activedirectory
$Excel=New-Object -Com Excel.Application
$Book=$Excel.Workbooks.Add()
#$Book.workSheets.item(3).delete()
#$Book.WorkSheets.item(2).delete()
$Book.WorkSheets.item(1).Name="Computers"
$Sheet=$Book.WorkSheets.Item(1)
$Sheet.Cells.Item(1,1)="Name"
$Sheet.Columns.Item(1).columnWidth=10
$Sheet.Cells.Item(1,2)="Operating system"
$Sheet.Columns.Item(2).columnWidth=25
$Sheet.Cells.Item(1,3)="IP"
$Sheet.Columns.Item(3).columnWidth=25
$Sheet.Cells.Item(1,4)="Мemory"
$Sheet.Columns.Item(4).columnWidth=13
$Sheet.Cells.Item(1,5)="RAM tot"
$Sheet.Columns.Item(5).columnWidth=7

$Sheet.Cells.Item(1,6)="CPU cores"
$Sheet.Columns.Item(6).columnWidth=7
$Sheet.Cells.Item(1,7)="CPU speed"
$Sheet.Columns.Item(7).columnWidth=7
$Sheet.Cells.Item(1,8)="CPU"
$Sheet.Columns.Item(8).columnWidth=25


$Sheet.Cells.Item(1,9)="CORES CPU"
$Sheet.Columns.Item(9).columnWidth=10
$Sheet.Cells.Item(1,10)="VIDEO"
$Sheet.Columns.Item(10).columnWidth=35
$Sheet.Cells.Item(1,11)="Hard drive"
$Sheet.Columns.Item(11).columnWidth=30

$Sheet.Cells.Item(1,12)="Motherboard"
$Sheet.Columns.Item(12).columnWidth=25
$Sheet.Cells.Item(1,13)="Network"
$Sheet.Columns.Item(13).columnWidth=45

$Sheet.UsedRange.Interior.ColorIndex=5
$Sheet.UsedRange.Font.ColorIndex=20
$Sheet.UsedRange.Font.Bold=$True
$sheet.Rows.Item(1).HorizontalAlignment=3
$Row=2

get-ADcomputer -Filter * | Sort-Object name | Select-Object name | foreach {
$_.name + '-----------'
if ((Test-connection $_.name -count 2 -quiet) -eq "True"){
$Sheet.Cells.Item($Row,1)=$_.name
#Система
$sys=Get-WmiObject -computername $_.name Win32_OperatingSystem
$IpAdd=Get-WmiObject Win32_NetworkAdapterConfiguration -computername $_.name #| Select IPAddress

$Sheet.Cells.Item($Row,2)=$sys.caption+"`n"+$sys.csdversion
$Sheet.Cells.Item($Row,3)="`n" + $IpAdd.IPAddress

#Память
$ram=Get-WmiObject -computername $_.name Win32_Physicalmemory
foreach ($dimm in $ram){$mem=$mem + $dimm.capacity
$dimms=$dimms +1}
$speed=$ram[0].speed
$Sheet.Cells.Item($Row,4)=($mem / 1Gb).tostring("F00")+"GB`n"+$dimms+"`n"+$speed+"Mhz"
$mem=0
$dimms=0

$ram_tot=Get-WmiObject Win32_PhysicalMemory -ComputerName $_.name | Measure-Object -Property capacity -Sum | % {[Math]::Round(($_.sum / 1GB),2)}
$Sheet.Cells.Item($Row,5)= $ram_tot

#Процессор
$cpuCores=Get-WmiObject Win32_Processor -computername $_.name | Select Name,Manufacturer,Caption, NumberOfCores,NumberOfLogicalProcessors, DeviceID, CurrentClockSpeed #,CurrentVoltage,DataWidth,L2CacheSize,L3CacheSize,Status
$Sheet.Cells.Item($Row,6)=$cpuCores.NumberOfCores
$Sheet.Cells.Item($Row,7)=$cpuCores.CurrentClockSpeed
$Sheet.Cells.Item($Row,8)=$cpuCores.name #+"`n"+$cpu.caption +"`n +$cpu.SocketDesignation

#Видеокарта
$video=""
foreach ($card in Get-WmiObject -computername $_.name Win32_videoController){
if ($card.AdapterRAM -gt 0){
$video=$video+$card.name+"`n"+($card.AdapterRAM/1Mb).tostring("F00")+"MB`n"}}
$Sheet.Cells.Item($Row,10)=$video.TrimEnd("`n")

#Диск
$disk=""
foreach ($hard in Get-WmiObject -computername $_.name win32_diskdrive){
if ($hard.MediaType.ToLower().StartsWith("fixed")){
$disk=$disk+(($hard.size)/1Gb).tostring("F00")+"GB - "+$hard.model+"`n"}}
$Sheet.Cells.Item($Row,11)=$disk.TrimEnd("`n")

#Материнская плата
$mb=Get-WmiObject -computername $_.name Win32_BaseBoard
$Sheet.Cells.Item($Row,12)=$mb.Manufacturer+"`n"+$mb.Product

#Сеть
$net=""
foreach ($card in Get-WmiObject -computername $_.name Win32_NetworkAdapter -Filter "NetConnectionStatus>0"){
$net=$net+$card.name+"`n"}
$Sheet.Cells.Item($Row,13)=$net.TrimEnd("`n")


$Row=$Row + 1
}}
$Sheet.UsedRange.WrapText=1
$Sheet.Rows.Item(1).AutoFilter()
$Sheet.UsedRange.EntireRow.AutoFit()
$sheet.UsedRange.Cells.borders.TintAndShade=1
$sheet.UsedRange.VerticalAlignment=2
$Excel.visible=$True
#$book.SaveAs("C:comps.xlsx")
#$excel.Quit()

 

 

modified good script https://kadmin.ru/powershell-inventarizatsiya/

Tags: powershell, AD microsoft

Добавить комментарий
JComments
http://shablony-dle.ru
kinofank.ru.