Script to check local machine info

Throughout my career I have noticed issues with build consistency across servers. As this is a recurring and seemingly never-ending problem I tried to find a script that could be run on a bunch of servers to check their configuration.

What I hoped to find was something that you could pipe a text file of servernames (or specify an OU in AD) and get the information pushed out to an Excel spreadsheet where you could easily manipulate the data. Alas I haven’t been able to find anything even remotely like what I’m looking for, so decided to start work on one myself.

While the final result might be a bit of a way off I have completed a preliminary script that you can use immediately. It will provide information on the local machine you run the script on. A text file is outputted to a directory that you can set.

It brings back information on disks, processors, memory, pagefile, IP address, search suffixes, DNS server and also performs an NS lookup of the server so you can be sure there is an entry.

I hope to expand this when I get time, but thought I would put it up now so others can use it. Let me know if you can think of ways to expand it.

Be sure to add your own DNS Server and file share information.

##################################################
# Script  : PCInfo.ps1
# Author  : Tom Anderson
# Date    : 15-08-2013
# Purpose : Provide quick overview of a server. To be used
#         : after building a server or in lieu of an audit.
# History :
################################################## 

#### Set parameters for output filename
$date = Get-Date -UFormat "%d-%m-%Y"
$ComputerName = hostname
$DNSServer = DNSServerName
$file = New-Item -type file "\\servername\share\$ComputerName-$date.txt" -Force

#### Get Disk information
'-=Disk Information=-' | out-file $file -append
$Disks = Get-WmiObject Win32_LogicalDisk -Filter "DriveType='3'"
foreach ($Disk in $Disks) {
$DiskGB = [math]::round($Disk.Size/1073741824, 0)
'Drive: ' + $Disk.DeviceID + "`t" + 'Disk size: ' + $DiskGB + 'Gb' | out-file $file -append
}
"`n" | out-file $file -append

#### Get Processor information
'-=Processor Information=-' | out-file $file -append
$Processors = Get-WmiObject win32_processor
foreach ($Processor in $Processors) {
'Processor cores: ' + "`t" + $Processor.numberOfCores | out-file $file –append
'Logical processors: ' + "`t" + $Processor.NumberOfLogicalProcessors | out-file $file –append
}
"`n" | out-file $file -append

#### Get Memory information
'-=Memory Information=-' | out-file $file -append
$RAM = Get-WmiObject Win32_ComputerSystem
$RAMGB = [math]::round($RAM.TotalPhysicalMemory/1024/1024/1024, 0)
'Memory size: ' + "`t" + "`t" + $RAMGB + 'Gb'  | out-file $file –append
"`n" | out-file $file -append

#### Get Pagefile information
'-=Pagefile Information=-' | out-file $file -append
$pagefiles = Get-WmiObject Win32_PageFileSetting
foreach ($pagefile in $pagefiles) {
$PagefileGB = [math]::round($pagefile.MaximumSize/1024, 0)
'Location: ' + "`t" + "`t" + $pagefile.Name | out-file $file –append
'Size: ' + "`t" + "`t" + "`t" + $PagefileGB + 'Gb' | out-file $file –append
}
"`n" | out-file $file -append

#### Get Network information information
'-=NIC Information=-' | out-file $file -append
$NICS = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Select-Object -Property [a-z]* -ExcludeProperty IPX*,WINS*
foreach ($NIC in $NICS) {
'Adapter name: ' + "`t" + "`t" + $NIC.Description  | out-file $file –append
'IP Address: ' + "`t" + "`t" + $NIC.IPAddress | out-file $file –append
'Search suffixes: ' + "`t" + $NIC.DNSDomainSuffixSearchOrder | out-file $file –append
'DNS Servers: ' + "`t" + "`t" + $NIC.DNSServerSearchOrder | out-file $file –append
"`n" | out-file $file –append
}

#### Lookup DNS entry
'-=NSLookup of host entry=-' | out-file $file -append
nslookup $ComputerName $DNSServer | out-file $file –append
Posted in Guides Tagged with: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*