Server Inventory Script
Below mentioned script is Powershell based script. Copy the below script in notepad and save it as .ps1 extension and put in one folder and create one notepad named as Machines.txt and update with server names.
Once you run the script then you will get the details like Host name, Operation System with SP, Bit , IP Operating System , serial number, RAM, Memory, Manufacturer, Model, Domain, Processor, No. Of Processors, Processor speed, Machine Type , Local Administrators in Spreadsheet.
===============================================================================
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excelbook = $Excel.Workbooks.Add()
$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(1,1) = “Computer Name”
$Sheet.Cells.Item(1,2) = “Operation System with SP ”
$Sheet.Cells.Item(1,3) = “Bit”
$Sheet.Cells.Item(1,4) = “Serial Number”
$Sheet.Cells.Item(1,5) = “IP”
$Sheet.Cells.Item(1,6) = “RAM”
$Sheet.Cells.Item(1,7) = “HDD”
$Sheet.Cells.Item(1,8) = “Manufacturer”
$Sheet.Cells.Item(1,9) = “Model”
$Sheet.Cells.Item(1,10) = “Domain”
$Sheet.Cells.Item(1,11) = “Processor”
$Sheet.Cells.Item(1,12) = “No of Processors”
$Sheet.Cells.Item(1,13) = “Processor Speed”
$Sheet.Cells.Item(1,14) = “Machine Type”
$Sheet.Cells.Item(1,15) = “Local Administrators”
$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 8
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True
$intRow = 2
$Computers = Get-Content “C:\Machines.txt”;
foreach ($Computer in $Computers)
{
$Hostname = (Get-WMIObject -computer $Computer -class
Win32_OperatingSystem).csname
if($Hostname -eq $null)
{
$Sheet.Cells.Item($intRow,1) = $Computer
$FK = $Sheet.Cells.Item($intRow,1)
$FK.Font.ColorIndex = 3
$FK.Font.Bold = $True
$Sheet.Cells.Item($intRow,2) = $null
$Sheet.Cells.Item($intRow,3) = $null
$Sheet.Cells.Item($intRow,4) = $null
$Sheet.Cells.Item($intRow,5) = $null
$Sheet.Cells.Item($intRow,6) = $null
$Sheet.Cells.Item($intRow,7) = $null
$Sheet.Cells.Item($intRow,8) = $null
$Sheet.Cells.Item($intRow,9) = $null
$Sheet.Cells.Item($intRow,10) = $null
$Sheet.Cells.Item($intRow,11) = $null
$Sheet.Cells.Item($intRow,12) = $null
$Sheet.Cells.Item($intRow,13) = $null
$Sheet.Cells.Item($intRow,14) = $null
}
else
{
$serveros = (Get-WMIObject -computer $Computer -class
Win32_OperatingSystem).Caption
$sp = (Get-WMIObject -computer $Computer -Class Win32_Operatingsystem).csdversion
$OSSP = $serveros + ” ” + $sp
$bit = (Get-WmiObject -computer $Computer -class
Win32_OperatingSystem).OSArchitecture
$serialnumber = (Get-WMIObject -computer $Computer -Class Win32_BIOS).Serialnumber
$sample = (Get-WMIObject -computer $Computer Win32_ComputerSystem
).Totalphysicalmemory
$RAM = [math]::round($sample/1gb,0)
$make = (Get-WMIObject -computer $Computer -Class Win32_BIOS).Manufacturer
$model = (get-wmiobject -computer $Computer -Class win32_computersystem).model
$domain = (get-wmiobject -computer $Computer -Class win32_computersystem).domain
$i = 0
$k = 0
$logical = 0
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName
$Computer | ? {$_.IPEnabled}
foreach ($Network in $Networks)
{
if($i -eq 0)
{
$IPAddress = $Network.IpAddress[0]
#IP details
#$Sheet.Cells.Item($intRow,5) = $IPAddress
$i = $i + 1
}
else {}
}
$Processors = Get-WmiObject Win32_processor -ComputerName $Computer
foreach ($processor in $Processors)
{
$processorname = $processor.name
$core = $processor.NumberOfCores
$logical = $processor.NumberOfLogicalProcessors
if($logical -ge 0)
{ }
else{
$logical = 1
}
$k = $k + 1
$p = Get-WmiObject -computer $Computer -Class Win32_Processor |
Select-Object -ExpandProperty Name
$speed = [string]$p
$final = $speed.split()[-1]
}
#$cores = @($processors).count
$total = $logical * $k
$size = 0
$size1 = 0
$disks = Get-WmiObject -ComputerName $Computer -Class Win32_LogicalDisk –
Filter “DriveType = 3”;
foreach($disk in $disks)
{ [float]$size1 = $disk.Size;
[float]$size = $size + $size1;
}
$sizeInGB = [Math]::Round($size / 1073741824, 2);
$computer = $computer.toupper()
$ADMINS = get-wmiobject -computername $computer -query “select * from
win32_groupuser where
GroupComponent=””Win32_Group.Domain=’$computer’,Name=’administrators'””” | %
{$_.partcomponent}
$s = 0
foreach ($ADMIN in $ADMINS)
{
$admin = $admin.replace(“\\$computer\root
\cimv2:Win32_UserAccount.Domain=”,””) # trims the results for a user
$admin = $admin.replace(“\\$computer\root\cimv2:Win32_Group.Domain=”,””) #
trims the results for a group
$admin = $admin.replace(‘”,Name=”‘,”\”)
$admin = $admin.REPLACE(“”””,””)#strips the last ”
switch($s)
{
0 { $admin0 = $admin; $s = $s + 1; }
1 { $admin1 = $admin; $s = $s + 1; }
2 { $admin2 = $admin; $s = $s + 1; }
3 { $admin3 = $admin; $s = $s + 1; }
4 { $admin4 = $admin; $s = $s + 1; }
5 { $admin5 = $admin; $s = $s + 1; }
6 { $admin6 = $admin; $s = $s + 1; }
7 { $admin6 = $admin; $s = $s + 1; }
8 { $admin6 = $admin; $s = $s + 1; }
9 { $admin6 = $admin; $s = $s + 1; }
10 { $admin6 = $admin; $s = $s + 1; }
11 { $admin6 = $admin; $s = $s + 1; }
default { }
}
$localadmins = $admin0 +” ; ” + $admin1 + ” ; ” + $admin2 + ” ; ” + $admin3
+ ” ; ” + $admin4 + ” ; ” + $admin5 + ” ; ” + $admin6 + ” ; ” + $admin7 + ” ; ” +
$admin8 + ” ; ” + $admin9 + ” ; ” + $admin10 + ” ; ” + $admin11
}
$Sheet.Cells.Item($intRow,1) = $Hostname
$Sheet.Cells.Item($intRow,2) = $OSSP
$Sheet.Cells.Item($intRow,3) = $bit
if($model -eq “Virtual Machine”)
{
$Sheet.Cells.Item($intRow,4) = “NA”
$Sheet.Cells.Item($intRow,8) = “NA”
$Sheet.Cells.Item($intRow,14) = $model
}
else
{
$Sheet.Cells.Item($intRow,4) = $serialnumber
$Sheet.Cells.Item($intRow,8) = $make
$Sheet.Cells.Item($intRow,14) = “Physical Machine”
}
$Sheet.Cells.Item($intRow,5) = $IPAddress
$Sheet.Cells.Item($intRow,6) = [string]$RAM + ” ” + “GB”
$Sheet.Cells.Item($intRow,7) = $sizeInGB
#$Sheet.Cells.Item($intRow,8) = $make
$Sheet.Cells.Item($intRow,9) = $model
$Sheet.Cells.Item($intRow,10) = $domain
$Sheet.Cells.Item($intRow,11) = $processorname
$Sheet.Cells.Item($intRow,12) = $total
$Sheet.Cells.Item($intRow,13) = $final
$Sheet.Cells.Item($intRow,15) = $localadmins
}
$intRow = $intRow + 1
}
$WorkBook.EntireColumn.AutoFit()
$date = (get-date -Format ddMMMyyyy-hhmmsstt)
$Excelbook.SaveAs(“C:\serverinventory.xlsx”)
$Excelbook.Close()
$Excel.Quit()
Најдобри девизни брокери. https://mk.forex-stock-bitcoin-brokers.com
Forex részvény. https://hu.forex-stock-bitcoin-brokers.com
you’ve a fantastic weblog here! would you like to make some invite posts on my blog?
dark web drug marketplace drug markets dark web