-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-HardwareOSInfo.ps1
215 lines (186 loc) · 8.34 KB
/
Get-HardwareOSInfo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
Function Get-HardwareOSInfo{
<#
.SYNOPSIS
Function to pull Hardware & OS info from a machine (prints to console and passes out object with data)
by Steven Wight
.DESCRIPTION
Get-HardwareOSInfo -ComputerName <Hostname> -Domain <domain> (default = POSHYT)
.EXAMPLE
Get-HardwareOSInfo Computer01
.Notes
You may need to edit the Domain depending on your environment (find $Domain)
#>
[CmdletBinding()]
Param(
[Parameter()] [String] [ValidateNotNullOrEmpty()] $ComputerName,
[Parameter()] [String] [ValidateNotNullOrEmpty()] $Domain = "POSHYT"
)
#Clear Variables encase function has been used before in session (never know!)
$Computer = $AdCheck = $PathTest = $CPUInfo = $PhysicalMemory = $computersystem = $NICinfo = $Monitors = $OSinfo = $BIOSinfo = $OSReleaseID = $Hyperthreading = $disk = $MachineInfoObj = $null
# Get Computer info from AD
try{
$Computer = (Get-ADComputer $ComputerName -properties DNSHostname,description,OperatingSystem -server $Domain -ErrorAction stop)
$AdCheck = $true
}Catch{
Write-Host -ForegroundColor Red "Machine $($ComputerName) not found in AD"
$Computer = $_.Exception.Message
$AdCheck = $false
}
# Check machine is online
if($True -eq $AdCheck){
$PathTest = Test-Connection -Computername $Computer.DNSHostname -BufferSize 16 -Count 1 -Quiet
if($false -eq $PathTest){
#Output machine is offline to the console
Write-host -ForegroundColor Red "Issues connecting to $($ComputerName)"
#Flush local DNS cache
Write-host -ForegroundColor Red "Flushing DNS"
ipconfig /flushdns | out-null
#Resolve DNS for machine
Write-host -ForegroundColor Red "Resolving DNS name for $($ComputerName)"
$DNSCheck = (Resolve-DnsName $Computer.DNSHostname -ErrorAction SilentlyContinue)
#If DNS is resolved, re ping
if($null -eq $DNSCheck){
Write-host -ForegroundColor Red "DNS entry found,Re-pinging $($ComputerName)"
$PathTest = Test-Connection -Computername $Computer.DNSHostname -BufferSize 16 -Count 1 -Quiet
}
}
} #End of If ADcheck is True
#if Machine is online
if($True -eq $PathTest) {
#Output machine is online to the console
Write-host -ForegroundColor Green "$($ComputerName) is online"
#Get Machine Info
#Grab CPU info
try{
$CPUInfo = (Get-WmiObject Win32_Processor -ComputerName $Computer.DNSHostname -ErrorAction Stop)
}catch{
$CPUInfo.Name = $_.Exception.Message
}
#Grab RAM info
Try{
$PhysicalMemory = Get-WmiObject CIM_PhysicalMemory -ComputerName $Computer.DNSHostname -ErrorAction Stop | Measure-Object -Property capacity -Sum | ForEach-Object { [Math]::Round(($_.sum / 1GB), 2) }
}catch{
$PhysicalMemory = $_.Exception.Message
}
#Grab Computer syste info
try{
$computersystem = (Get-wmiobject -ComputerName $Computer.DNSHostname win32_computersystem -Property * -ErrorAction Stop)
}catch{
$computersystem.Model = $_.Exception.Message
}
#Grab NIC Info
try{
$NICinfo = (Get-WmiObject win32_networkadapterconfiguration -ComputerName $Computer.DNSHostname -ErrorAction Stop | Where-Object {$null -ne $_.ipaddress})
}Catch{
$NICinfo.ipaddress = $_.Exception.Message
}
#Grab Monitor Info
Try{
$Monitors = Get-WmiObject -Namespace "root\WMI" -Class "WMIMonitorID" -ComputerName $Computer.DNSHostname -ErrorAction SilentlyContinue
}Catch{
$Monitors = $_.Exception.Message
}
#Grab Graphics card info
Try{
$GraphicsCard = Get-WmiObject win32_VideoController -ComputerName $Computer.DNSHostname -ErrorAction SilentlyContinue
}Catch{
$GraphicsCard = $_.Exception.Message
}
#Grab OS info
Try{
$OSinfo = (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer.DNSHostname -ErrorAction Stop | Select-Object * )
}Catch{
$OSinfo.version = $_.Exception.Message
}
#Grab BIOS info
Try{
$BIOSinfo = (Get-WmiObject -Class Win32_BIOS -ComputerName $Computer.DNSHostname -ErrorAction Stop)
}Catch{
$BIOSinfo.SerialNumber = $_.Exception.Message
}
#Grab OS Release ID
Try{
$OSReleaseID = Invoke-Command -ComputerName $Computer.DNSHostname -scriptblock {(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ReleaseId -ErrorAction SilentlyContinue).ReleaseId}
}Catch{
$OSReleaseID = $_.Exception.Message
}
#Work out if Hyperthreading is enabled
Try{
$Hyperthreading = ($CPUInfo | measure-object -Property NumberOfLogicalProcessors -sum).Sum -gt $($CPUInfo | measure-object -Property NumberOfCores -sum).Sum
}Catch{
$Hyperthreading = $_.Exception.Message
}
#Grab info on c: drive (screw other drives...)
Try{
$disk = (Get-WmiObject Win32_LogicalDisk -ComputerName $computer.DNSHostname -Filter "DeviceID='C:'" -ErrorAction Stop | Select-Object FreeSpace,Size)
}Catch{
$disk = $_.Exception.Message
}
# build object to use to fill CSV with data and print to screen
$MachineInfoObj = [pscustomobject][ordered] @{
ComputerName = $ComputerName
Description = $Computer.description
SerialNo = $BIOSinfo.SerialNumber
IPaddress = [string]$NICinfo.ipaddress
Mac = $NICinfo.Macaddress
Model = $computersystem.Model
Manufacturer = $computersystem.Manufacturer
Screens = $Monitors.count
GraphicsCard = $GraphicsCard.name
VideoDriverVersion = $GraphicsCard.DriverVersion
VideoRes = $GraphicsCard.VideoModeDescription
Domain = $Domain
OS = $Computer.OperatingSystem
CPU = [string]$CPUInfo.Name
NoOfCPU = $computersystem.NumberOfProcessors
Hyperthreading = $Hyperthreading
RAM_GB = $PhysicalMemory
C_Drive_Size_GB = $disk.Size/1GB
C_Drive_Free_Space_GB = $disk.FreeSpace/1GB
Build_day = ([WMI]'').ConvertToDateTime($OSinfo.installDate)
Build_version = $OSinfo.version
Build_number = $OSinfo.BuildNumber
OS_Release = $OSReleaseID
OS_Architecture = $OSinfo.OSArchitecture
}
#output info to console
Write-host "$($MachineInfoObj)"
#Return Info
return $MachineInfoObj
}else{#If machine wasn't online
#Output machine is online to the console
Write-host -ForegroundColor Red "$($ComputerName) is offline"
# build object to use to fill CSV with data and print to screen (Set Variables to "offline")
# build object to use to fill CSV with data and print to screen (Set Variables to "offline")
$MachineInfoObj = [pscustomobject][ordered] @{
ComputerName = $ComputerName
Description = $Computer.description
SerialNo = "offline"
IPaddress = "offline"
Mac = "offline"
Model = "offline"
Manufacturer = "offline"
Screens = "offline"
GraphicsCard = "offline"
VideoDriverVersion = "offline"
VideoRes = "offline"
Domain = $Domain
OS = $Computer.OperatingSystem
CPU = "offline"
NoOfCPU = "offline"
Hyperthreading = "offline"
RAM_GB = "offline"
C_Drive_Size_GB = "offline"
C_Drive_Free_Space_GB = "offline"
Build_day = "offline"
Build_version = "offline"
Build_number = "offline"
OS_Release = "offline"
OS_Architecture = "offline"
}
#output info to console
Write-host "$($MachineInfoObj)"
#Return Info
return $MachineInfoObj
}# End of If
}# end of Function