Solved

Inventory Servers in Domain with Powershell

Posted on 2014-02-19
17
1,231 Views
Last Modified: 2014-03-04
Hi experts,

I need some help from the PowerShell gurus out there as I am still a novice and learning powershell.

I would like to get an inventory of all the servers in a domain whether the servers are physical or Virtual. Find info such as OS, RAM, CPU, IP Address, make and model, group them by site and then export the output to .csv

If anyone can help this would save me a lot of time.

Many thanks.
0
Comment
Question by:damejen
  • 9
  • 8
17 Comments
 
LVL 10

Assisted Solution

by:Prashant Girennavar
Prashant Girennavar earned 500 total points
Comment Utility
Sure,

Below is the script which you can use it to query all the servers from AD and then do a WMI query to get the information abut RAM , CPU etc.

$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()

# Insert text in to first row.
$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(1,1) = "Server"
$Sheet.Cells.Item(1,2) = "FQDNName"
$Sheet.Cells.Item(1,3) = "Manufacturer"
$Sheet.Cells.Item(1,4) = "Model"
$Sheet.Cells.Item(1,5) = "TotalPhysicalMemory"
$Sheet.Cells.Item(1,6) = "isVirtual" 
$Sheet.Cells.Item(1,7) = "SerialNumber" 
$Sheet.Cells.Item(1,8) = "BiosVersion"
$Sheet.Cells.Item(1,9) = "IPAddress"
$Sheet.Cells.Item(1,10) = "MACAddress"
$Sheet.Cells.Item(1,11) = "IPSubnet"
$Sheet.Cells.Item(1,12) = "DefaultGateway"
$Sheet.Cells.Item(1,13) = "Type"
$Sheet.Cells.Item(1,14) = "DHCPUse"
$Sheet.Cells.item(1,15) = "PasswordLastSet"
$Sheet.Cells.Item(1,16) = "DistinguisedName"
$Sheet.Cells.item(1,17) = "OperatingSystem"
$Sheet.Cells.Item(1,18) = "ServicePack"
$Sheet.Cells.item(1,19) = "BuildNumber"
$Sheet.Cells.Item(1,20) = "BuildType"
$Sheet.Cells.Item(1,21) = "Version"
$Sheet.Cells.Item(1,22) = "Administrator"
$Sheet.Cells.Item(1,23) = "SerialNumberOS"
$Sheet.Cells.Item(1,24) = "ServerOSConcat"




# Format it to make it a little more fancy.
$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 15
$WorkBook.Font.Bold = $True

# Go to the second row.
$intRow = 2


$Domain = Get-Content C:\DomainControllers.txt
Foreach($DC in $Domain)
{
Remove-Item C:\ADcomputer.csv -Force
import-module activeDirectory
$a = Get-ADComputer -server $DC -filter * -properties Operatingsystem
$list= @()
Foreach ($os in $a)
{
If($os.Operatingsystem -match "windows Server *")
{
$list += $os | Select-Object name
}
}
$list | Export-Csv C:\adcomputer.csv -Force -NoTypeInformation



# Select text file which contains list of workstations to query.

$arrComputers = Import-Csv C:\adcomputer.csv | Select-Object Name -ExpandProperty name

# Get currently logged in username, client name, manufacturer and model from Win32_ComputerSystem class.
foreach ($strComputer in $arrComputers){

try { $colItems = Get-WmiObject Win32_ComputerSystem -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer

foreach($objItem in $colItems) {
$Sheet.Cells.Item($intRow,1) = $objItem.Name
$Sheet.Cells.Item($intRow,2) = ($objItem | % {$_.DNSHOSTName +'.'+$_.domain}).ToLower()
$Sheet.Cells.Item($intRow,3) = $objItem.Manufacturer
$Sheet.Cells.Item($intRow,4) = $objItem.Model
$Sheet.Cells.Item($intRow,5) = ($objItem.TotalPhysicalMemory/1024MB)
if($objItem.Model -like "VMWare*")
{
$Sheet.Cells.Item($intRow,6) = "Yes"
}
Else
{
$Sheet.Cells.Item($intRow,6)="No"
}
}



# Get workstation serial number from Win32_BIOS class.
$colItems = Get-WmiObject Win32_BIOS -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer

foreach($objItem in $colItems) {
$Sheet.Cells.Item($intRow,7) = $objItem.SerialNumber
if($objItem.BiosVersion -eq $null)
{
$Sheet.Cells.Item($intRow,8)= "Unknown"
}
Else
{
$Sheet.Cells.Item($intRow,8) = $objItem.BiosVersion[0]
}
}
	
#Get OperatingSystme Imforamtion from Win32_OperatingSystem

$colItems = Get-WmiObject Win32_OperatingSystem -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer

foreach($objItem in $colItems) {
$Sheet.Cells.Item($intRow,17) = $objItem.Name | % { $_.Split("|")[0] }
$Sheet.Cells.Item($intRow,18) = $objItem.servicepackmajorversion
$Sheet.Cells.Item($intRow,19) = $objItem.BuildNumber
$Sheet.Cells.Item($intRow,20) = $objItem.BuildType
$Sheet.Cells.Item($intRow,21) = $objItem.Version
$Sheet.Cells.Item($intRow,23) = $objItem.SerialNumber
$Sheet.cells.Item($intRow,24) = "=(A$($intRow) & Q$($intRow))"

	}
	
#Get Local Administrator Information
$computer = [ADSI](”WinNT://” + $strComputer + “,computer”)
$Group = $computer.psbase.children.find(”Administrators”)
[string]$members = ($Group.psbase.invoke(”Members”) | %{$_.GetType().InvokeMember(”Adspath”, ‘GetProperty’, $null, $_, $null)}) -replace ('WinNT://DOMAIN/' + $server + '/'), '' -replace ('WinNT://DOMAIN/', 'DOMAIN\') -replace ('WinNT://', '')
$m = $members.Replace(" ",",")
$Sheet.Cells.Item($intRow,22) = $m.Replace("/","\")
	
#Get DN and PasswordLastSet for computer from ActiveDirectory Query

Import-Module ActiveDirectory
$m = Get-ADComputer -Server $DC -identity $strComputer -Properties * | Select-Object -Property PasswordLastSet , DistinguishedName
$Sheet.Cells.Item($intRow , 15) = $m.passwordlastset.ToString("dd/MM/yyyy hh:mm tt")
$Sheet.Cells.Item($intRow , 16) = $m.DistinguishedName


# Get IP address and MAC address of the enabled network adapter from Win32_NetworkAdapaterConfiguration class.
$colItems = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer | where{$_.IPEnabled -eq “$true”}

foreach($objItem in $colItems) {
$Sheet.Cells.Item($intRow,9) = $objItem.IPAddress[0]
$Sheet.Cells.Item($intRow,10) = $objItem.MACAddress
$Sheet.Cells.Item($intRow,11) = $objItem.IPSubnet
$Sheet.Cells.Item($intRow,12) = $objItem.DefaultIPGateway
$Sheet.Cells.Item($intRow,13) = "IPv4"
$Sheet.Cells.Item($intRow,14) = $objItem.DHCPEnabled

$intRow+=1	
}

}

# Append workstation name to log file if uncontactable and show message in output window to advise.
    catch {
        Write-Host "Could not contact $($strComputer)" -ForegroundColor Red
        Out-File -FilePath C:\OCCPAR\couldnotreach1.txt -InputObject $strComputer -Append -Force
        }
}
}

Open in new window


(Note - I have taken this script from internet and modified according to my need)

You just need to create a text file (C:\Domaincontrollers.txt) and place all Domain contollers from differnet domain where you want to query servers

The script will populate the information in a excel file.

Make sure to run this script where RSAT is installed.

Let me know if you have any questions

Thanks,

-Prashant Girennavar.
1
 

Author Comment

by:damejen
Comment Utility
Hi Prashant,

Thanks for the script I've created a .txt file with my Domain controllers though when I run the script it tells me "cannot find path C:\ADcomputer.csv because it does not exits?

Also it only writes to the 2nd line of the excel document and it overwrites the same line with each server it discovers...

What could be the issue, is there anything else i need to do before running the script?
0
 
LVL 10

Accepted Solution

by:
Prashant Girennavar earned 500 total points
Comment Utility
ok

Let me know if below works for you

$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()

# Insert text in to first row.
$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(1,1) = "Server"
$Sheet.Cells.Item(1,2) = "FQDNName"
$Sheet.Cells.Item(1,3) = "Manufacturer"
$Sheet.Cells.Item(1,4) = "Model"
$Sheet.Cells.Item(1,5) = "TotalPhysicalMemory"
$Sheet.Cells.Item(1,6) = "isVirtual" 
$Sheet.Cells.Item(1,7) = "SerialNumber" 
$Sheet.Cells.Item(1,8) = "BiosVersion"
$Sheet.Cells.Item(1,9) = "IPAddress"
$Sheet.Cells.Item(1,10) = "MACAddress"
$Sheet.Cells.Item(1,11) = "IPSubnet"
$Sheet.Cells.Item(1,12) = "DefaultGateway"
$Sheet.Cells.Item(1,13) = "Type"
$Sheet.Cells.Item(1,14) = "DHCPUse"
$Sheet.Cells.item(1,15) = "PasswordLastSet"
$Sheet.Cells.Item(1,16) = "DistinguisedName"
$Sheet.Cells.item(1,17) = "OperatingSystem"
$Sheet.Cells.Item(1,18) = "ServicePack"
$Sheet.Cells.item(1,19) = "BuildNumber"
$Sheet.Cells.Item(1,20) = "BuildType"
$Sheet.Cells.Item(1,21) = "Version"
$Sheet.Cells.Item(1,22) = "Administrator"
$Sheet.Cells.Item(1,23) = "SerialNumberOS"
$Sheet.Cells.Item(1,24) = "ServerOSConcat"




# Format it to make it a little more fancy.
$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 15
$WorkBook.Font.Bold = $True

# Go to the second row.
$intRow = 2


$Domain = Get-Content C:\DomainControllers.txt
Foreach($DC in $Domain)
{
Remove-Item C:\ADcomputer.csv -Force
import-module activeDirectory
$a = Get-ADComputer -server $DC -filter * -properties Operatingsystem
$list= @()
Foreach ($os in $a)
{
If($os.Operatingsystem -match "windows Server *")
{
$list += $os | Select-Object name
}
}
$list | Export-Csv C:\adcomputer.csv -Force -NoTypeInformation



# Select text file which contains list of workstations to query.

$arrComputers = Import-Csv C:\adcomputer.csv | Select-Object Name -ExpandProperty name

# Get currently logged in username, client name, manufacturer and model from Win32_ComputerSystem class.
foreach ($strComputer in $arrComputers){

try { $colItems = Get-WmiObject Win32_ComputerSystem -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer

foreach($objItem in $colItems) {
$Sheet.Cells.Item($intRow,1) = $objItem.Name
$Sheet.Cells.Item($intRow,2) = ($objItem | % {$_.DNSHOSTName +'.'+$_.domain}).ToLower()
$Sheet.Cells.Item($intRow,3) = $objItem.Manufacturer
$Sheet.Cells.Item($intRow,4) = $objItem.Model
$Sheet.Cells.Item($intRow,5) = ($objItem.TotalPhysicalMemory/1024MB)
if($objItem.Model -like "VMWare*")
{
$Sheet.Cells.Item($intRow,6) = "Yes"
}
Else
{
$Sheet.Cells.Item($intRow,6)="No"
}
}



# Get workstation serial number from Win32_BIOS class.
$colItems = Get-WmiObject Win32_BIOS -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer

foreach($objItem in $colItems) {
$Sheet.Cells.Item($intRow,7) = $objItem.SerialNumber
if($objItem.BiosVersion -eq $null)
{
$Sheet.Cells.Item($intRow,8)= "Unknown"
}
Else
{
$Sheet.Cells.Item($intRow,8) = $objItem.BiosVersion[0]
}
}
	
#Get OperatingSystme Imforamtion from Win32_OperatingSystem

$colItems = Get-WmiObject Win32_OperatingSystem -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer

foreach($objItem in $colItems) {
$Sheet.Cells.Item($intRow,17) = $objItem.Name | % { $_.Split("|")[0] }
$Sheet.Cells.Item($intRow,18) = $objItem.servicepackmajorversion
$Sheet.Cells.Item($intRow,19) = $objItem.BuildNumber
$Sheet.Cells.Item($intRow,20) = $objItem.BuildType
$Sheet.Cells.Item($intRow,21) = $objItem.Version
$Sheet.Cells.Item($intRow,23) = $objItem.SerialNumber
$Sheet.cells.Item($intRow,24) = "=(A$($intRow) & Q$($intRow))"

	}
	
#Get Local Administrator Information
$computer = [ADSI](”WinNT://” + $strComputer + “,computer”)
$Group = $computer.psbase.children.find(”Administrators”)
[string]$members = ($Group.psbase.invoke(”Members”) | %{$_.GetType().InvokeMember(”Adspath”, ‘GetProperty’, $null, $_, $null)}) -replace ('WinNT://DOMAIN/' + $server + '/'), '' -replace ('WinNT://DOMAIN/', 'DOMAIN\') -replace ('WinNT://', '')
$m = $members.Replace(" ",",")
$Sheet.Cells.Item($intRow,22) = $m.Replace("/","\")
	
#Get DN and PasswordLastSet for computer from ActiveDirectory Query

Import-Module ActiveDirectory
$m = Get-ADComputer -Server $DC -identity $strComputer -Properties * | Select-Object -Property PasswordLastSet , DistinguishedName
$Sheet.Cells.Item($intRow , 15) = $m.passwordlastset.ToString("dd/MM/yyyy hh:mm tt")
$Sheet.Cells.Item($intRow , 16) = $m.DistinguishedName


# Get IP address and MAC address of the enabled network adapter from Win32_NetworkAdapaterConfiguration class.
$colItems = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer | where{$_.IPEnabled -eq “$true”}

foreach($objItem in $colItems) {
$Sheet.Cells.Item($intRow,9) = $objItem.IPAddress[0]
$Sheet.Cells.Item($intRow,10) = $objItem.MACAddress
$Sheet.Cells.Item($intRow,11) = $objItem.IPSubnet
$Sheet.Cells.Item($intRow,12) = $objItem.DefaultIPGateway
$Sheet.Cells.Item($intRow,13) = "IPv4"
$Sheet.Cells.Item($intRow,14) = $objItem.DHCPEnabled


}
$intRow+=1

}

# Append workstation name to log file if uncontactable and show message in output window to advise.
    catch {
        Write-Host "Could not contact $($strComputer)" -ForegroundColor Red
        Out-File -FilePath C:\OCCPAR\couldnotreach1.txt -InputObject $strComputer -Append -Force
        }
}
}
                                            

Open in new window


Thanks,

-Prashant Girennavar.
1
 

Author Comment

by:damejen
Comment Utility
Hi Prishant,

Thanks again for looking into this, although it doesn't seem to quite work for me.
The second issue of the text being overwritten in row 2 is still occuring rather than the script populating the other rows. So its only showing one row of server information, though it gets overwritten when it finds the next server.

The information it is pulling out is exactly what im looking for though apart from the issue above.
0
 
LVL 10

Expert Comment

by:Prashant Girennavar
Comment Utility
The script works for me.

$intRow +=1; is the variable which is responsible to increment the Rows in excel. Check it is proper.

If it does not work , copy your code and paste it here.

Thanks,

-Prashant Girennavar.
0
 

Author Comment

by:damejen
Comment Utility
This is the code.

Line 41 in the original was $intRow = 2
I changed that to $intRow +=1 as you suggested. Same result.
0
 
LVL 10

Expert Comment

by:Prashant Girennavar
Comment Utility
I dont see the code.

Can you please send it once again.

Thanks,

-Prashant Girennavar.
0
 

Author Comment

by:damejen
Comment Utility
sorry here you go, see attached.
Get-Servers.txt
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:damejen
Comment Utility
Hi Prashant

Im not sure where I'm going wrong with this script. I've added the RSAT to the server i'm running the script on member 2012 server.

I seem to get the following.

It creates the excel file, but then I get the following (please see attachments.)
28-02-2014-16-52-21.png
28-02-2014-16-52-50.png
0
 
LVL 10

Expert Comment

by:Prashant Girennavar
Comment Utility
Do you have the windows server 2008 DC???

basically script is unable to contact do a query of DC as I suspect you are using w2k3 for DC query.

I suggest you to put the DC which has w2k8 as OS in domaincontoller.txt


Let me know if you don't have w2k8.

Thanks,

-Prashant Girennavar.
0
 

Author Comment

by:damejen
Comment Utility
Hi Prashant,

No unfortunately the environment I'm using does not have a W2k8 DC's
FFL and DFL is at W2K3. We only have W2K3 DC's at the moment.

Many thanks for you help Prishant.
0
 
LVL 10

Assisted Solution

by:Prashant Girennavar
Prashant Girennavar earned 500 total points
Comment Utility
ok.

Then , you need to extract all the servers from AD and put them in a text file.

I have modified the script , Please populate all the server list in C:\Temp\Servers.txt

and run the script

$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()

# Insert text in to first row.
$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(1,1) = "Server"
$Sheet.Cells.Item(1,2) = "FQDNName"
$Sheet.Cells.Item(1,3) = "Manufacturer"
$Sheet.Cells.Item(1,4) = "Model"
$Sheet.Cells.Item(1,5) = "TotalPhysicalMemory"
$Sheet.Cells.Item(1,6) = "isVirtual" 
$Sheet.Cells.Item(1,7) = "SerialNumber" 
$Sheet.Cells.Item(1,8) = "BiosVersion"
$Sheet.Cells.Item(1,9) = "IPAddress"
$Sheet.Cells.Item(1,10) = "MACAddress"
$Sheet.Cells.Item(1,11) = "IPSubnet"
$Sheet.Cells.Item(1,12) = "DefaultGateway"
$Sheet.Cells.Item(1,13) = "Type"
$Sheet.Cells.Item(1,14) = "DHCPUse"
$Sheet.Cells.item(1,15) = "PasswordLastSet"
$Sheet.Cells.Item(1,16) = "DistinguisedName"
$Sheet.Cells.item(1,17) = "OperatingSystem"
$Sheet.Cells.Item(1,18) = "ServicePack"
$Sheet.Cells.item(1,19) = "BuildNumber"
$Sheet.Cells.Item(1,20) = "BuildType"
$Sheet.Cells.Item(1,21) = "Version"
$Sheet.Cells.Item(1,22) = "Administrator"
$Sheet.Cells.Item(1,23) = "SerialNumberOS"
$Sheet.Cells.Item(1,24) = "ServerOSConcat"




# Format it to make it a little more fancy.
$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 15
$WorkBook.Font.Bold = $True

# Go to the second row.
$intRow = 2


$arrComputers = Get-Content C:\Temp\Servers.txt

# Get currently logged in username, client name, manufacturer and model from Win32_ComputerSystem class.
foreach ($strComputer in $arrComputers){
    $strComputer =   $env:computername
        try { $colItems = Get-WmiObject Win32_ComputerSystem -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer
        
        foreach($objItem in $colItems) {
            $Sheet.Cells.Item($intRow,1) = $objItem.Name
            $Sheet.Cells.Item($intRow,2) = ($objItem | % {$_.DNSHOSTName +'.'+$_.domain}).ToLower()
            $Sheet.Cells.Item($intRow,3) = $objItem.Manufacturer
            $Sheet.Cells.Item($intRow,4) = $objItem.Model
            $Sheet.Cells.Item($intRow,5) = ($objItem.TotalPhysicalMemory/1024MB)
            if($objItem.Model -like "VMWare*"){ $Sheet.Cells.Item($intRow,6) = "Yes"}
            Else {$Sheet.Cells.Item($intRow,6)="No"}
        }

        # Get workstation serial number from Win32_BIOS class.
        $colItems = Get-WmiObject Win32_BIOS -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer
        foreach($objItem in $colItems) { $Sheet.Cells.Item($intRow,7) = $objItem.SerialNumber
            if($objItem.BiosVersion -eq $null){ $Sheet.Cells.Item($intRow,8)= "Unknown"}
            Else {$Sheet.Cells.Item($intRow,8) = $objItem.BiosVersion[0]}
        }
	
        #Get OperatingSystme Imforamtion from Win32_OperatingSystem

        $colItems = Get-WmiObject Win32_OperatingSystem -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer

        foreach($objItem in $colItems) {
        $Sheet.Cells.Item($intRow,17) = $objItem.Name | % { $_.Split("|")[0] }
        $Sheet.Cells.Item($intRow,18) = $objItem.servicepackmajorversion
        $Sheet.Cells.Item($intRow,19) = $objItem.BuildNumber
        $Sheet.Cells.Item($intRow,20) = $objItem.BuildType
        $Sheet.Cells.Item($intRow,21) = $objItem.Version
        $Sheet.Cells.Item($intRow,23) = $objItem.SerialNumber
        $Sheet.cells.Item($intRow,24) = "=(A$($intRow) & Q$($intRow))"
        }
	
        #Get Local Administrator Information
        $computer = [ADSI](”WinNT://” + $strComputer + “,computer”)
        $Group = $computer.psbase.children.find(”Administrators”)
        [string]$members = ($Group.psbase.invoke(”Members”) | %{$_.GetType().InvokeMember(”Adspath”, ‘GetProperty’, $null, $_, $null)}) -replace ('WinNT://DOMAIN/' + $server + '/'), '' -replace ('WinNT://DOMAIN/', 'DOMAIN\') -replace ('WinNT://', '')
        $m = $members.Replace(" ",",")
        $Sheet.Cells.Item($intRow,22) = $m.Replace("/","\")
	


        # Get IP address and MAC address of the enabled network adapter from Win32_NetworkAdapaterConfiguration class.
        $colItems = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer | where{$_.IPEnabled -eq “$true”}

        foreach($objItem in $colItems) {
        $Sheet.Cells.Item($intRow,9) = $objItem.IPAddress[0]
        $Sheet.Cells.Item($intRow,10) = $objItem.MACAddress
        $Sheet.Cells.Item($intRow,11) = $objItem.IPSubnet
        $Sheet.Cells.Item($intRow,12) = $objItem.DefaultIPGateway
        $Sheet.Cells.Item($intRow,13) = "IPv4"
        $Sheet.Cells.Item($intRow,14) = $objItem.DHCPEnabled

        $intRow+=1	
        }
    }

# Append workstation name to log file if uncontactable and show message in output window to advise.
    catch {
        Write-Host "Could not contact $($strComputer)" -ForegroundColor Red
        Out-File -FilePath C:\couldnotreach1.txt -InputObject $strComputer -Append -Force
        }
}

Open in new window


Let me know if you need additional help

Thanks,

-Prashant Girennavar.
0
 

Author Comment

by:damejen
Comment Utility
Hi Prashant,

Ok I've created another .txt file with my DC's under C:\Temp\Servers.txt.
Though now I seem to only get results from the Server I'm running the script from. and then the script completes. No other errors.
03-03-2014-12-13-32.png
0
 
LVL 10

Expert Comment

by:Prashant Girennavar
Comment Utility
Make sure you dont have spaces in the text file.

I would suggest you to put only 2 servers in a text file and run the script.

let me know your findings.

-Prashant Girennavar.
0
 

Author Comment

by:damejen
Comment Utility
I've only put two Dc's without any spaces in the txt file e.g DC01,DC02

But it still only gives me output for the server I'm running the script on.  No other information on any other servers is being produced.

There are no errors from the script, just only getting information on one server, the one im running the script on.
0
 
LVL 10

Assisted Solution

by:Prashant Girennavar
Prashant Girennavar earned 500 total points
Comment Utility
Ok ,

Try this.

$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()

# Insert text in to first row.
$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(1,1) = "Server"
$Sheet.Cells.Item(1,2) = "FQDNName"
$Sheet.Cells.Item(1,3) = "Manufacturer"
$Sheet.Cells.Item(1,4) = "Model"
$Sheet.Cells.Item(1,5) = "TotalPhysicalMemory"
$Sheet.Cells.Item(1,6) = "isVirtual" 
$Sheet.Cells.Item(1,7) = "SerialNumber" 
$Sheet.Cells.Item(1,8) = "BiosVersion"
$Sheet.Cells.Item(1,9) = "IPAddress"
$Sheet.Cells.Item(1,10) = "MACAddress"
$Sheet.Cells.Item(1,11) = "IPSubnet"
$Sheet.Cells.Item(1,12) = "DefaultGateway"
$Sheet.Cells.Item(1,13) = "Type"
$Sheet.Cells.Item(1,14) = "DHCPUse"
$Sheet.Cells.item(1,15) = "PasswordLastSet"
$Sheet.Cells.Item(1,16) = "DistinguisedName"
$Sheet.Cells.item(1,17) = "OperatingSystem"
$Sheet.Cells.Item(1,18) = "ServicePack"
$Sheet.Cells.item(1,19) = "BuildNumber"
$Sheet.Cells.Item(1,20) = "BuildType"
$Sheet.Cells.Item(1,21) = "Version"
$Sheet.Cells.Item(1,22) = "Administrator"
$Sheet.Cells.Item(1,23) = "SerialNumberOS"
$Sheet.Cells.Item(1,24) = "ServerOSConcat"




# Format it to make it a little more fancy.
$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 15
$WorkBook.Font.Bold = $True

# Go to the second row.
$intRow = 2


$arrComputers = Get-Content C:\Temp\Servers.txt

# Get currently logged in username, client name, manufacturer and model from Win32_ComputerSystem class.
foreach ($strComputer in $arrComputers){
           try { $colItems = Get-WmiObject Win32_ComputerSystem -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer
        
        foreach($objItem in $colItems) {
            $Sheet.Cells.Item($intRow,1) = $objItem.Name
            $Sheet.Cells.Item($intRow,2) = ($objItem | % {$_.DNSHOSTName +'.'+$_.domain}).ToLower()
            $Sheet.Cells.Item($intRow,3) = $objItem.Manufacturer
            $Sheet.Cells.Item($intRow,4) = $objItem.Model
            $Sheet.Cells.Item($intRow,5) = ($objItem.TotalPhysicalMemory/1024MB)
            if($objItem.Model -like "VMWare*"){ $Sheet.Cells.Item($intRow,6) = "Yes"}
            Else {$Sheet.Cells.Item($intRow,6)="No"}
        }

        # Get workstation serial number from Win32_BIOS class.
        $colItems = Get-WmiObject Win32_BIOS -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer
        foreach($objItem in $colItems) { $Sheet.Cells.Item($intRow,7) = $objItem.SerialNumber
            if($objItem.BiosVersion -eq $null){ $Sheet.Cells.Item($intRow,8)= "Unknown"}
            Else {$Sheet.Cells.Item($intRow,8) = $objItem.BiosVersion[0]}
        }
	
        #Get OperatingSystme Imforamtion from Win32_OperatingSystem

        $colItems = Get-WmiObject Win32_OperatingSystem -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer

        foreach($objItem in $colItems) {
        $Sheet.Cells.Item($intRow,17) = $objItem.Name | % { $_.Split("|")[0] }
        $Sheet.Cells.Item($intRow,18) = $objItem.servicepackmajorversion
        $Sheet.Cells.Item($intRow,19) = $objItem.BuildNumber
        $Sheet.Cells.Item($intRow,20) = $objItem.BuildType
        $Sheet.Cells.Item($intRow,21) = $objItem.Version
        $Sheet.Cells.Item($intRow,23) = $objItem.SerialNumber
        $Sheet.cells.Item($intRow,24) = "=(A$($intRow) & Q$($intRow))"
        }
	
        #Get Local Administrator Information
        $computer = [ADSI](”WinNT://” + $strComputer + “,computer”)
        $Group = $computer.psbase.children.find(”Administrators”)
        [string]$members = ($Group.psbase.invoke(”Members”) | %{$_.GetType().InvokeMember(”Adspath”, ‘GetProperty’, $null, $_, $null)}) -replace ('WinNT://DOMAIN/' + $server + '/'), '' -replace ('WinNT://DOMAIN/', 'DOMAIN\') -replace ('WinNT://', '')
        $m = $members.Replace(" ",",")
        $Sheet.Cells.Item($intRow,22) = $m.Replace("/","\")
	


        # Get IP address and MAC address of the enabled network adapter from Win32_NetworkAdapaterConfiguration class.
        $colItems = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace "root\CIMV2" -ErrorAction stop -ComputerName $strComputer | where{$_.IPEnabled -eq “$true”}

        foreach($objItem in $colItems) {
        $Sheet.Cells.Item($intRow,9) = $objItem.IPAddress[0]
        $Sheet.Cells.Item($intRow,10) = $objItem.MACAddress
        $Sheet.Cells.Item($intRow,11) = $objItem.IPSubnet
        $Sheet.Cells.Item($intRow,12) = $objItem.DefaultIPGateway
        $Sheet.Cells.Item($intRow,13) = "IPv4"
        $Sheet.Cells.Item($intRow,14) = $objItem.DHCPEnabled

        	$intRow+=1
        }
		
    }

# Append workstation name to log file if uncontactable and show message in output window to advise.
    catch {
        Write-Host "Could not contact $($strComputer)" -ForegroundColor Red
        Out-File -FilePath C:\couldnotreach1.txt -InputObject $strComputer -Append -Force
        }
}
                                            

Open in new window


-Prashant Girennavar.
0
 

Author Closing Comment

by:damejen
Comment Utility
This powershell script is originally intended to gather W2k8 Domain, Domain servers information, it has been amended by its creator Prashant Girennavar for W2K3 Domain
0

Featured Post

Too many email signature updates to deal with?

Do you feel like you are taking up all of your time constantly visiting users’ desks to make changes to email signatures? Wish you could manage all signatures from one central location, easily design them and deploy them quickly to users? Well, there is an easy way!

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…
In this video tutorial I show you the main steps to install and configure  a VMware ESXi6.0 server. The video has my comments as text on the screen and you can pause anytime when needed. Hope this will be helpful. Verify that your hardware and BIO…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now