Recently, we rolled out new computers and one of the challenges is collecting asset inventory. In the past it was very manually as in you had to write down the serial numbers for the computer and monitors and then update the asset inventory system (yes automated systems exist, but that is not something we currently have.
Someone made a comment of how difficult this was and impossible to collect and it irritated me enough that I thought I should automate it.
I did some googling and discovered that using WMI you can obtain the model number and serial number for the Computer, Monitors, docking station and webcam. With that knowledge and borrowing from some other scripts, I came up with a script that will collect the information and email the information to you.
The only flaw I have found in the script, is Dell does a poor job of putting the serial number into the monitor firmware, meaning you do not always get the entire serial number, but otherwise it works great. If you are looking to grab system serial numbers in a very easy way and get away from writing them down, this is the way.
The script is set to look for a certain model for Webcams and for Docking stations. (Note the Surface Dock 1, does not expose its serial number to WMI. The Surface Dock 2 does).
In the Example below, you will need to Modify the name to the webcam that you currently have installed in your environment.
"WebCam Information" | Out-File -Append -FilePath c:\temp\asset.txt
Get-CimInstance Win32_PnPEntity | where name -match 'Lenovo 500 RGB Camera' | Format-List Name | Out-File -Append -FilePath c:\temp\asset.txt
The script will run and prompt you for an email address and the Person who the asset inventory is for. If you are logged on as the user, it will also collect that information.
Hopefully, this will help someone else facing this challenge.
You can also down the script from my Github site.
#####Define Variables#####
$EmailFrom = "xxx@xxx.xxx"
$toaddress = Read-Host -Prompt 'Input Your Email Address'
$Subject = Read-Host -Prompt 'Enter the users who Inventory this is For'
$attachment = "c:\temp\asset.txt"
##########Remove File if it exists###############
Remove-Item c:\temp\asset.txt
##########Asset Inventory Script###############
whoami | Out-File -Append -FilePath c:\temp\asset.txt
hostname | Out-File -Append -FilePath c:\temp\asset.txt
"Computer Model" | Out-File -Append -FilePath c:\temp\asset.txt
wmic csproduct get name | Out-File -Append -FilePath c:\temp\asset.txt
"Computer Serial Number" | Out-File -Append -FilePath c:\temp\asset.txt
get-ciminstance win32_bios | format-list serialnumber, Manufacture | Out-File -Append -FilePath c:\temp\asset.txt
"Surface Dock Information" | Out-File -Append -FilePath c:\temp\asset.txt
get-CimInstance -Namespace "root/Surface" -Class "SurfaceDockComponent" | Where-Object ComponentName -like Microcontroller | Format-List DeviceName,DockSerialNumber,Version | Out-File -Append -FilePath c:\temp\asset.txt
"Monitor Information" | Out-File -Append -FilePath c:\temp\asset.txt
function Decode {
If ($args[0] -is [System.Array]) {
[System.Text.Encoding]::ASCII.GetString($args[0])
}
Else {
"Not Found"
}
}
ForEach ($Monitor in Get-WmiObject WmiMonitorID -Namespace root\wmi) {
$Manufacturer = Decode $Monitor.ManufacturerName -notmatch 0
$Name = Decode $Monitor.UserFriendlyName -notmatch 0
$Serial = Decode $Monitor.SerialNumberID -notmatch 0
echo "Manufacturer: $Manufacturer`nName: $Name`nSerial Number: $Serial `n" | Out-File -Append -FilePath c:\temp\asset.txt
}
Out-File -Append -FilePath c:\temp\asset.txt
"WebCam Information" | Out-File -Append -FilePath c:\temp\asset.txt
Get-CimInstance Win32_PnPEntity | where name -match 'Lenovo 500 RGB Camera' | Format-List Name | Out-File -Append -FilePath c:\temp\asset.txt
Get-CimInstance Win32_PnPEntity | where name -match 'Logitech' | Format-List Name | Out-File -Append -FilePath c:\temp\asset.txt
Get-CimInstance Win32_PnPEntity | where name -match 'Logi'| Format-List Name | Out-File -Append -FilePath c:\temp\asset.txt
#########Send Email Messager########################
Send-MailMessage -From 'XX Asset Inventory <qbai@quarles.com>' -To $toaddress -Subject $Subject -Body "Automated Powershell Script of Asset Inventory Email" -Attachments $attachment -SmtpServer 'xxxxxx@xxxxx.xxx'