computer asset inventory

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
jvierra
Posts: 14552
Joined: Tue May 22, 2007 9:57 am
Contact:

computer asset inventory

Post by jvierra »

Here is a blog entry with a good WMI-Help utility that willretrieve the MS help for a specific WMI class:

http://powershelllive.com/blogs/lunch/r ... &AndTags=1


User avatar
dee
Posts: 35
Joined: Wed Mar 05, 2008 6:17 am

computer asset inventory

Post by dee »

I did the following:

Code: Select all

Get-WmiObject -Query "SELECT * FROM Win32_Service" Where {$_.StartMode -eq "Disabled" -and $_.Status -eq "OK"} -ComputerName $_ -Credential $cred | Select-Object Name,Status,StartMode,DisplayName

But, got "A parameter cannot be found that matches parameter name "Where"....

User avatar
dee
Posts: 35
Joined: Wed Mar 05, 2008 6:17 am

computer asset inventory

Post by dee »

That worked. Win32_BIOS select-object SerialNumber had the Dell Asset Tag! Awesome! :)

User avatar
baldcat
Posts: 8
Joined: Sun Feb 03, 2008 12:52 pm

computer asset inventory

Post by baldcat »

Hey guys,, this is good to see..

I'm trying something similar, and I'm a total novice, so I bits and pieces from everywhere,,,

$strComputers = @()$ou = [ADSI]"LDAP://DC=domain,DC=COM,DC=AU"foreach ($child in $ou.psbase.Children) { if ($child.ObjectCategory -like '*computer*') { $strComputers += $child.Name }} $resultsBlank = ""
$ResultsFile = "C:ListCompSpec.txt"
foreach ($strComputer in $strComputers) {$colItems = get-wmiobject -class "Win32_Processor" -namespace "rootCIMV2" -computername $strComputerforeach ($objItem in $colItems) {$strTotalSpeed = [math]::round( ( $objItem.CurrentClockSpeed ) )if ($strTotalSpeed > 2) {"Name: " + $objItem.Name + " Speed: " + $strTotalSpeed | out-file -filepath $ResultsFile -append}}}


I'm trying to get a read out of all the PCs on the netwrork that have a processor speed of 2 or less.

I dev guys don't know any powershell so I'm all alone... Anyone ?

User avatar
dee
Posts: 35
Joined: Wed Mar 05, 2008 6:17 am

computer asset inventory

Post by dee »

wow.. awesome quest you have there. Isn't great that we have a forum like so. I think this must be the best source out there for help. good luck baldcat, im sure one of these gurus will be able to help. I'm wanting your thread as well to learn, I'm new to powershell as well.

thanks,
dee

deepakm@rice.edu

jvierra
Posts: 14552
Joined: Tue May 22, 2007 9:57 am
Contact:

computer asset inventory

Post by jvierra »

For baldcat -

Let's drop the "procedural" in favor of "Declaritive".

You would like to do the following.

Get all computer in the domain with processors speeds greate than "n".

In PoSh this might look something like this:

Get-DomainComputers | Where { $_.speed > $n }

Unfortunately processor speed is not an attribute of a computer object in the domain AD database. This will cause us to have to query each computer individually using WMI most likely.

We will modify the pseudo code to reflect this.
Get-DomainComputers | gwmi -Computer $_ -query "select * from | Win32_Processor where speed > $n"} | select name

This, when complete, should return only matching computers.

YOur method of select computers will be very slow because it will retrieve every object in AD while looking for a computer object. If your domain is large, 10000 plus AD objects, this can take quite a bit of time. Use the following method to ask AD to do the filtering for you.

Code: Select all

function Get-DomainComputerList{
     $search = [System.DirectoryServices.DirectorySearcher]""
     $search.Filter = "(objectclass=computer)"
     $search.Findall()|%{$_.GetDirectoryEntry()}|%{$_.CN}
}
(fixed code block to return array of strings)
Execute the above by typing "get-domaincomputerlist". This will return an array of computer names. In practice I would probably return the ADSI objects raw but for the sake of this example we will extract only the name or "CN" value. It will be packaged in a collection or "PSCustomObject" types.

Try the above and then pass it to your wmi query. If the list is reasonable in size it will execute very fast. If you have thousands of computers then you may have to wait for some time for it to complete as each computer will have to be contacted in sequence.



jvierra2008-03-18 12:05:44

jvierra
Posts: 14552
Joined: Tue May 22, 2007 9:57 am
Contact:

computer asset inventory

Post by jvierra »

These items are not kept in the registry or exposed through any normal interfaces. YOu can get them via SECEDIT, RSoP or SECPOL.MSC. You would then have to parse the output file.

User avatar
donj
Posts: 416
Joined: Thu Nov 16, 2006 9:02 pm

computer asset inventory

Post by donj »

There's currently no way, in a script, to "crack open" a GPO and read the individual settings. This is a major shortcoming in GPO that Microsoft is aware of - there was much discussion of it at the recent Directory Experts Conference - and is something they plan to address in the future.

Certain of these settings can be queried by using ADSI and the WinNT provider, since AD is backward-compatible. However, it won't work in 2008 domains where you have granular policies applies - it'll only grab the top-level domain policy.

You'll find some samples at http://www.microsoft.com/technet/script ... x?mfr=true.

UPDATE: Actually, SDM Software's GPO cmdlets CAN crack open a GPO and read individual settings. My bad.donj2008-04-08 10:08:37

User avatar
donj
Posts: 416
Joined: Thu Nov 16, 2006 9:02 pm

computer asset inventory

Post by donj »

1.
Installed memory might be in Win32_ComputerSystem. "Free space" isn't calculated like that, though. You could query the performance counter info. I'd recommend getting the WMI Browser (Tools Zone here) and looking around in the rootcimv2 namespace.

2.
Win32_LogicalDisk

Don't know what you mean by "current partitions." Win32_LogicalDisk or Win32_Partition, depending on OS version, should let you see them all.

RAID level and stuff is hardware-specific. Your hardware vendor would need to provide the info.

3.
PowerShell doesn't have any built-in way of evaluating ranges of IP addresses. You might do something like...

switch -regex ($ip) {
"^d{1,3}.d{1,3}.12d{1,3}$" { "xxx.xxx.12.xxx" }
"^d{1,3}.d{1,3}.13d{1,3}$" { "xxx.xxx.13.xxx" }
}

That uses a regular expression to look at the third octet of the address and display something.

4.
The DefaultIPGateway and IPSubnet properties of Win32_NetworkAdapterConfiguration aren't doing it for you?

5.
Thank you! I recommend "Windows PowerShell: TFM" (grin) by Don Jones and Jeffery Hicks.

User avatar
dee
Posts: 35
Joined: Wed Mar 05, 2008 6:17 am

computer asset inventory

Post by dee »

Thank you! wow such a fast response! You are awesome donj! another question. How would I query/filter the software's installed to see if a partictular software is installed?

Thanks,
Dee

Locked