PowerShell Cmdlets for Network Inventory
March 15, 2009 7 Comments
This past week I spent a few evenings on my balcony coding the final bits of Project Full Moon. Full Moon is a set of PowerShell Cmdlets for NetPoint, which are targeted at helping IT Pros automate repetitive system and asset management tasks.
In this post I’ll show how you can use these commands to make your life a bit easier. Here are some scenarios I’ll walk through:
- You’re interested in getting a list of the apps installed on a certain system
- Some of your Dell workstations are having issues with their NVIDIA graphics cards. You need to apply a driver update to all of these systems.
- It’s that time of the year to buy new hardware. You need to determine if there are any systems that need a hard drive upgrade.
- There’s a new virus in the wild. You need to ensure all of your systems are protected with up to date virus definitions.
So let’s get started! First let’s add the NetPoint PowerShell SnapIn and get a list of our network inventory cmdlets:
Add-PSSnapin Neutex*
Get-Command -PSSnapin Neutex*
PowerShell will list the 20 cmdlets available to us:
Get-NetAntiVirus
Get-NetBIOSGet-NetCDROMDriveGet-NetDiskDrive- Get-NetFirewall
Get-NetFloppyDriveGet-NetLogicalDiskGet-NetMemoryGet-NetModemGet-NetMonitorGet-NetNetworkAdapterGet-NetOperatingSystemGet-NetPatchGet-NetPrinterGet-NetProcessorGet-NetProgramGet-NetServiceGet-NetSoundDeviceGet-NetSystemGet-NetVideoController
Now we're ready to tackle our scenarios.
You're interested in getting a list of the apps installed on a certain system
Get-NetProgram can be used to retrieve a set of programs. Running this command by itself will return all programs that have been installed on our network (even those that have been uninstalled). Like all of our other network inventory commands, it also accepts a set of parameters (app name, publisher, how often it's used, etc.) that can be used to filter its results. Here is the script that will get us the results we want:
Get-NetProgram -System maui -Uninstalled $False | % { $_.DisplayName } | sort -unique
This command starts out by retrieving all of the apps installed on the system named maui. By default, we’ll get a whole set of information about each app, but we only want the app names so we’ll pipe this into % { $_.DisplayName } and sort it so we can easily get an idea of the installed apps.
Some of your Dell workstations are having issues with their NVIDIA graphics cards. You need to apply a driver update to all of these systems.
The data we need to target for this scenario is spread across two domains: video controller (NVIDIA graphics cards) and system (Dell workstations). We’ll use Get-VideoController in conjunction with Get-System to get the job done:
Get-NetVideoController -Name nvidia* -Uninstalled $False | Get-NetSystem -Manufacturer dell* | % { $_.ComputerSystemName } | sort -unique
Here we’re getting a list of all installed graphics cards whose name starts with NVIDIA. We then pipe this to Get-System with the Manufacturer parameter set. This will return all Dell systems that contain an NVIDIA graphics cards. The last two portions of this script will cause only the system names to be returned in alphabetical order.
You could use this output with the WMI cmdlets to install the driver update.
It’s that time of the year to buy new hardware. You need to determine if there are any systems that need a hard drive upgrade.
In this scenario, we’re interested in using the Get-NetLogicalDisk cmdlet as follows:
Get-NetLogicalDisk -DriveType "Local Disk" | where { $_.FreeSpace / $_.Size -lt .10 } | % { $_.ComputerSystemName }
The first portion of this script will get all partitions that are stored on hard disks (versus CDs, floppies, etc.). We proceed by using PowerShell’s where command to only get partitions that have less than 10% of free space and we pipe this to % { $_.ComputerSystemName } to only get a list of the system names.
There’s a new virus in the wild. You need to ensure all of your systems are protected with up to date virus definitions.
This scenario is a little more complex than the previous ones, however we can still solve it in two lines of PowerShell.
$i = Get-NetAntiVirus -Uninstalled $False -UptoDate $True | % { $_.ComputerSystemName } | sort -unique
Get-NetSystem | where {$i -notcontains $_.ComputerSystemName} | % { $_.ComputerSystemName } | sort -unique
The first line will get us names of all the systems that have an antivirus client with up to date virus definitions. The second line will subtract this list from all of the systems on our network using the where command, which leaves us with the unprotected systems. The WMI cmdlets could also be used here to install an updated antivirus client on these systems.
That pretty much sums up some of the basic scenarios you can address with NetPoint’s PowerShell Cmdlets. There is some documentation work that still needs to be sorted out, however you can expect to see the final bits online in a couple of weeks. In the meantime if you don’t already have a copy of NetPoint, you can get the free Express Edition here.
Pingback: Episode 1 of the NetPoint PowerShell Commands « Shannon Ma Virtualized
Pingback: Episode 76 – Don Jones on Security « PowerScripting Podcast
What if a user has two active video cards. From my experience powershell will not actually come up with anything for that computer and space will be blank.
Hi Jim,
The NetPoint PowerShell Commands will correctly detect a computer with two active video cards. NetPoint 2.6 was just released with a PowerGUI PowerPack that allows you to manage your systems. You can check it out at http://www.neutex.net and if you’d like to evaluate Pro just let me know and I can send you a trial license.
Shannon
Pretty great article, really helpful information. Never imagined I would obtain the facts I need in this article. I have been looking all around the net for some time now and was starting to get frustrated. Thankfully, I came across your internet site and received exactly what I had been browsing for.
Downloading the NetPoint.powerpack from:
http://powergui.org/servlet/KbServlet/download/2582-102-4157/NetPoint.powerpack
It has the powerpack-extension, but I can’t import (have confirmed method at: http://wiki.powergui.org/index.php/PowerPacks#Importing_PowerPacks_into_the_Administrative_Console
PowerGUI version: 2.0.0.1082
Error: “PowerShell Snapin ‘Neutex.NetPoint.Powershell’ is not installed. Please install this snapin and try again.”
I have tried this from a 2008R2-server and a windows7-box both generating the same error.
Could you help me here?
You’ll need to download NetPoint (http://www.neutex.net) before you can use the NetPoint PowerPack. NetPoint is a network inventory tool and the PowerPack allows you to view and remotely administer your systems through PowerGUI. Let me know if you have any questions about it. You can also find a video on it at http://www.neutex.net/videos/remote-desktop-management/.