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
Avatar of piattnd
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?
Avatar of Indyrb
Indyrb
Flag of United States of America image

ASKER

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.
Avatar of piattnd
piattnd

Do you use the same active directory domain or are they all their own AD domains?
Avatar of Indyrb
Indyrb
Flag of United States of America image

ASKER

All in same domain. Actually there is one child domain but I can do they seperately. My main goal is the root domain
Avatar of piattnd
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.
Avatar of Indyrb
Indyrb
Flag of United States of America image

ASKER

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.
Avatar of Indyrb
Indyrb
Flag of United States of America image

ASKER

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
Avatar of btan
btan

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Rich Rumble
Rich Rumble
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
ASKER CERTIFIED SOLUTION
Avatar of btan
btan

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Indyrb
Indyrb
Flag of United States of America image

ASKER

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
Active Directory
Active Directory

Active Directory (AD) is a Microsoft brand for identity-related capabilities. In the on-premises world, Windows Server AD provides a set of identity capabilities and services, and is hugely popular (88% of Fortune 1000 and 95% of enterprises use AD). This topic includes all things Active Directory including DNS, Group Policy, DFS, troubleshooting, ADFS, and all other topics under the Microsoft AD and identity umbrella.

86K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo