Powershel is a very helpful tool and can give power in IT Pro. So with Powershell continue to improve my small script that will be use as Asset Management for all the Hardware in my company.
Today i will explain all the changes in the script that i have done to get details from Computers and represent in GUI environment.
In previous article How to scan ip addresses range and get important details with Powershell GUI represent only 2 Properties of the Computers that scan:
- Ip Address
- Operating System
Now i have add more Properties to represent as
- RAM
- CPU
- Local Disk
- Computername
So let's start
First of all we must decide how can retrieve the above details from the remote computers.
In the past i wrote an article Use WMI with Powershell to Discover Monitor Information which explain exactly how can do this.
So let's do a test with the following commands to verify that get what we want
Get-WmiObject Win32_ComputerSystem | Select-Object caption,TotalPhysicalMemory
Get-WmiObject Win32_processor | Select-Object caption
Get-WMIObject Win32_Logicaldisk -filter "deviceid='C:'" | Select-Object Size
Now let's go to add these commands in our script.
I will take the following part of the code
$a..$b | ForEach-Object { $o = new-object psobject # New object
$o | add-member -membertype noteproperty -name ipaddress -value (gwmi Win32_PingStatus -Filter "Address='$c.$_'").ProtocolAddress | Out-Null
$o | add-member -membertype noteproperty -name OS -value (gwmi Win32_Operatingsystem -computername "$c.$_").Caption | Out-Null
$ arr += $o }
and i will change as follow
$a..$b | ForEach-Object {$o = new-object psobject # New object
$o | add-member -membertype noteproperty -name ipaddress -value (gwmi Win32_PingStatus -Filter "Address='$c.$_'").ProtocolAddress | Out-Null
$o | add-member -membertype noteproperty -name OS -value (gwmi Win32_Operatingsystem -computername "$c.$_").Caption | Out-Null
$o | add-member -membertype noteproperty -name Computername -value (gwmi Win32_ComputerSystem -computername "$c.$_").Caption | Out-Null
$o | add-member -membertype noteproperty -name TotalPhysicalram -value (gwmi Win32_ComputerSystem -computername "$c.$_").TotalPhysicalMemory | Out-Null
$o | add-member -membertype noteproperty -name CPU -value (gwmi Win32_processor -computername "$c.$_").Caption | Out-Null
$o | add-member -membertype noteproperty -name Localdisk -value (gwmi Win32_Logicaldisk -filter "deviceid='C:'" -computername "$c.$_").Size | Out-Null
$arr += $o
}
Now let's go to change the following part of the code that select the specific properties of the array
$arr | select-object -property ipaddress,OS
as follow
$arr | select-object -property ipaddress,OS,Computername,@{Name="TotalPhysicalram(GB)";e={$_.TotalPhysicalMemory /1GB -as [int]}},CPU,@{Name="Localdisk";e={$_.Size /1GB -as [int]}}
Now run the script, fill the ip addresses range and click in Scan button.
One important thing is how to fill the ip addresses.
In the First 3 parts must type 192.168.10 and not 192.168.10.
I have some issues in my script that will resolve it in the next article.s Some of them are:
- Very slow in the scan
- TotalPhysicalram and Localdisk not converted to GB
In case that you would like to learn Powershell because you have confuse with lot of info in the Internet you can use the technology Platform Pluralsight and find lot of training for Powershell
Have a nice weekend !
I hope to find useful this article.
I invite you to follow me on Twitter , Google+ or Facebook. If you have any questions, send email to me at info@askme4tech.com