-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-PcInventoryData.ps1
42 lines (31 loc) · 1.41 KB
/
Get-PcInventoryData.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
#region Credits
# Author: Federico Lillacci
# GitHub: https://github.com/tsmagnum
# Version: 1.0
# Date: 27/06/2023
#endregion
#results file, please customize the $logPath! Use a UNC path.
$logPath = "\\server\subdir\Pc_Inv\LogInventory\"
$logfile = (Get-Date).ToString('yyyyMMdd')+"_PcInventory.csv"
#PC name
$hostname = $env:COMPUTERNAME
#OS Info
$osInfo = Get-WmiObject -Class Win32_OperatingSystem
#OS Install Date - You can change the date format after .Tostring(
$installDate = (([WMI]'').ConvertToDateTime(($osInfo).InstallDate)).ToString("dd/MM/yyyy")
#OS Version
$osVersion = $osInfo.Version
#CPU Info
$cpuInfo = (Get-WmiObject Win32_Processor).Name
#installed memory sticks
$memorySticks = (Get-WmiObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum).Count
#total RAM
$memoryTotal = (Get-WmiObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum).Sum/1gb
#1st phyisical disk size
$physicalDiskQuery = "Select * from Win32_diskDrive where DeviceID like '%PHYSICALDRIVE0%'"
$physicalDiskSize = [math]::Round(((Get-WmiObject -Query $physicalDiskQuery).Size/1gb),0)
#formatting the results string
$results = "$hostname,$osVersion,$installDate,$cpuInfo,$memorySticks,$memoryTotal,$physicalDiskSize"
#displaying the results and adding them to the CSV file
Write-Host -ForegroundColor Cyan $results
Add-Content -Path $logPath$logfile -Value $results