Avatar of Indyrb
IndyrbFlag for United States of America asked on

Server inventory

I am looking for a script that will create an excel spreadsheet of all the servers in the environment

It would have
Server name:   Operating System: Manufacurer: Service Tag/Serial Number   Make and Model   IP address and if its a virtual machine or not. and also OU if in ADS.


Then also create a log of servers that are no longer available

I am hoping to get Windows , ESX, and Linux, Sun servers alike in the master spreadsheet, but not sure if that possible.

Can anyone help me get started?
PowershellVB ScriptActive Directory

Avatar of undefined
Last Comment
Indyrb

8/22/2022 - Mon
piattnd

That's quite the broad request there!  :)

Do you have any powershell scripting experience?  How many servers are you talking about?  Are they all on the same subnet or are they scattered across many subnets?
ASKER
Indyrb

No not really
I am talking about 2000+ servers across multiple subnets and sites.

I don't even know all the subnets used, as there is not a reverse dns lookup zone for everyone used.
piattnd

Do you use the same active directory domain or are they all their own AD domains?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
Indyrb

All in same domain. Actually there is one child domain but I can do they seperately. My main goal is the root domain
piattnd

Your best bet is to get the computer names from Active Directory OUs where the server computer objects are stored.  You can then use DNS to attempt to resolve the IP Address to a host name and log those to the excel spreadsheet.

The script you're looking for is not a simple script and would require you to understand the scripting language and build/troubleshoot.
ASKER
Indyrb

Anybody have examples of a vbs or powershell that will export
Server name:   Operating System: Manufacurer: Service Tag/Serial Number   Make and Model   IP address and if its a virtual machine or not. and also OU if in ADS. to an excel spreadsheet.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Indyrb

I came across this powershell script...
Can someone help me add device id c:\ disk size, free space and used space
pagefile
Ip address , subnet, default gateway, primarydns, secondarydns



param($X="C:\powershell.csv")

      [array]$Servers=@()
      [array]$array1 = @()

      cls

      New-Item -ItemType File $X -force | out-Null

      Add-Content $X "Server Name,Server Type,Serial Number,OS Version,OS Service Pack,Server Manufacture,Server Model,Server BIOS Version,Physical Memory GB,Number of CPUs,Number of Cores per CPU,Processor Description,Processor Speed GHz" | out-Null

      $X1 = (($X).Split("_").Get(0)) + "_unreachable.txt"

      New-Item -ItemType File $X1 -force | out-Null
      Add-Content $X1 "Computer Name `n" | out-Null

      Write-Host "Computer Serial Numbers will be wriiten to $X `n"
      Write-Host "Unreachable Computers will be written to $X1 `n`n"

      function FindServers {
      $OUpath = "" 
      $dn = $domain.distinguishedName
      if($OUpath) {$Servers = [ADSI]"LDAP://$OUpath,$dn"} else {$Servers = [ADSI]"LDAP://$dn"}
      $searcher = New-Object DirectoryServices.DirectorySearcher($Servers)
      $searcher.filter = "(objectClass=computer)"
      $Searcher.CacheResults = $true
      $Searcher.SearchScope = "Subtree"
      $Searcher.PageSize = 100
      $searcher.findall()
      }
      Write-Host "Please wait gathering computers from AD `n`n"
      $ServerList = @(FindServers)

      foreach ($item in $ServerList) {
      if(($item | select -Expand properties).operatingsystem | where {$_ -match "2000|2008|2003"}) {$array1 += (($item | select -Expand properties).cn)}

      }


      Write-Host "Please wait gathering inventry information from computers `n"
      foreach ($Computer in $array1) {Write-Host "." -NoNewline

      try {

      $ComputerSystem = @{}
      $Win32_ComputerSystem = $Null

      $Win32_ComputerSystem = (Get-WmiObject -ComputerName $Computer -Class Win32_ComputerSystem -ErrorAction SilentlyContinue) #class
      if ($Win32_ComputerSystem) {

      $Win32_BIOS = (Get-WmiObject -ComputerName $Computer -Class Win32_BIOS) #class

      $ComputerSystem.SerialNumber = ($Win32_BIOS.SerialNumber)
      if ($($ComputerSystem.SerialNumber) -notmatch "^VMware") {

      $ComputerSystem.BIOS_Version = ($Win32_BIOS.SMBIOSBIOSVersion)

      $ComputerSystem.Name = ($Win32_ComputerSystem.Name)
      $ComputerSystem.Manufacture = ($Win32_ComputerSystem.Manufacturer)
      $ComputerSystem.Model = ($Win32_ComputerSystem.Model)
      $ComputerSystem.PhysicalMemoryGB = (($Win32_ComputerSystem.TotalPhysicalMemory)/1GB -as [int])

      $OperatingSystem = (Get-WmiObject -computername $Computer -Class Win32_OperatingSystem) #class
      $ComputerSystem.OS = ($OperatingSystem.Name.split("|").Get(0))
      $ComputerSystem.SP = ($OperatingSystem.CSDVersion)



      $Win32_Processor = (Get-WmiObject -ComputerName $Computer -Class Win32_Processor) #class

      foreach ($processor in $Win32_Processor) {
      $ComputerSystem.NumberOfPhysicalCPUs = ($Win32_Processor | measure | select -exp count)
      $ComputerSystem.NumberOfCoresPerCPU = 0
      $ComputerSystem.NumberOfCoresPerCPU = ($processor.NumberOfCores)
      if(!($ComputerSystem.NumberOfCoresPerCPU)) {$ComputerSystem.NumberOfCoresPerCPU = 1}
      $ComputerSystem.ProcessorDescription = ($processor.Description)
      $ComputerSystem.ProcessorSpeedGHz = (($processor.MaxClockSpeed)/1000)

      if ($ComputerSystem.SerialNumber -notmatch "^VMWare") {$ComputerSystem.Type = "Physical"} else {$ComputerSystem.Type = "Virtual"}
      }
      Add-content $X "$($ComputerSystem.Name),$($ComputerSystem.Type),$($ComputerSystem.SerialNumber),$($ComputerSystem.OS),$($ComputerSystem.SP),$($ComputerSystem.Manufacture),$($ComputerSystem.Model),$($ComputerSystem.BIOS_Version),$($ComputerSystem.PhysicalMemoryGB),$($ComputerSystem.NumberOfPhysicalCPUs),$($ComputerSystem.NumberOfCoresPerCPU),$($ComputerSystem.ProcessorDescription),$($ComputerSystem.ProcessorSpeedGHz)" | Out-Null
      }
      }
      else {Write-Host "";"Could not reach computer $Computer , continuing to next computer";"";Add-Content $X1 $Computer}
      }catch {Write-Host "";"Could not reach computer $Computer , continuing to next computer";"";Add-Content $X1 $Computer}}
      Write-Host "*** Complete ***"
SOLUTION
btan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Indyrb

I am trying to combine a few of the samples. but run into a few road blocks.

In the example below.

if ($continue) (
I am query different get-wmi object -class XYZ
Then in $hash = @{
'example'=$xyz.variable;

isn't showing up

    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$True,
                   ValueFromPipeline=$True,
                   ValueFromPipelineByPropertyName=$True)]
        [Alias('name')]
        [string[]]$computername,
        [string]$logfile = 'failed.txt'
    )
    BEGIN {
        Del $logfile -ea SilentlyContinue
    }
    PROCESS {
        foreach ($computer in $computername) {
            $continue = $true
            try {
                $os = Get-WmiObject -class Win32_OperatingSystem `
                 -computer $computer -ea Stop
            } catch {
                $computer | out-file $logfile -append
                $continue = $false
            }
            if ($continue) {
                        $comp = Get-WmiObject -class Win32_ComputerSystem `
                 -computername $computer
                $bios = Get-WmiObject -class Win32_BIOS `
                 -computername $computer
                        $bios2 = Get-WmiObject -class Win32_BIOS `
                 -computername $computer
            
                $proc = Get-WmiObject -class Win32_Processor `
                 -computername $computer | Select -first 1
                $hash = @{
                    'ComputerName'=$computer;
                    'BIOSSerial'=$bios.serialnumber;
                              'BIOSManufacturer'=$bios.manufacturer;
                                                  'OSVersion'=$os.caption;
                    'OSBuild'=$os.buildnumber;
                    'SPVersion'=$os.servicepackmajorversion;
                    'OSArch'=$os.osarchitecture;
                    'ProcArch'=$proc.addresswidth;
         'Ram'=$comp.totalphysicalmemory
                }
                $obj = New-Object -TypeName PSObject -Property $hash
                Write-Output $obj
            }
        }
    }
}


get-serverinfo localhost only shows the orginal6-7 things