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.
This topic is 15 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
dee
Posts: 35
Last visit: Wed May 21, 2008 8:36 am

computer asset inventory

Post by dee »

also, the speed was very quick and I couldn't ask for it to be any quicker. I'm just not sure how to search for that file in any local disk of a particular server.


Also, how do I date format and truncate the "LastModified"?

Code: Select all

Get-WmiObject -Query "SELECT * FROM cim_datafile where name='c:program filesesetupdfileslastupd.ver'" -ComputerName $_ -Credential $cred |
	Select-Object Name,LastModified | Format-List
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

computer asset inventory

Post by jvierra »

I am going to stress this very heavily Dee. You really need to get a book or take a class in PowerShell. YOu are asing questions about each lin eof code. Many of these questions you are very close to having an answer for but it appears you lack some of the fundamentals. Save yourseld some frustration and get one of the many books on programming PowerShell.

The answer to your last questin is that you can't do it the way you are approaching the problem. You need to handle the property selection and formating manually in code in this case. The objects returned by WMI are not always complpetely decoded into NET types and you need to do this yourself. The ConvertToDateTime method I posted was a hint. It is one of the ways that WMI has been modified in NET and PoSH to make it more usable/convenient. You still need to do the individual programming steps.


To search through all disks of a server you would need to change teh dirve letter of the search or not use a drive letter. Using a drive letter an full path will be very fast. Not using a drive letter but using a full path will be very fast assumming no more that 10 disks.

To search across all disks use "filename=" instead of "name=". When using filename use only teh first part without the extension. Specifiy extension separately.

To get a list of all volumes try the following:
gwmi -query "select * from Win32_LogicalDisk where drivetype=3"|%{$_.Name}

You can use strin gmanipulation to add teh volume name to the file name so you can search through all local drives. If you need to search USB and other odd drive types then you will need to modify teh WHERE to include the correct types.




jvierra2008-04-28 10:38:58
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

computer asset inventory

Post by jvierra »

A little better explanation of how WMI works with files:

Code: Select all

PS> Get-WmiObject -Query "SELECT * FROM cim_datafile where filename='boot'"

Compressed  : False
Encrypted   : False
Size        :
Hidden      : True
Name        : <FONT color=#cc0000>c:boot.ini</FONT>
Readable    : True
System File :
Version     :
Writeable   : False

Compressed  : False
Encrypted   : False
Size        :
Hidden      : False
Name        : d:boot.ini
Readable    : True
System File :
Version     :
Writeable   : True

Compressed  : False
Encrypted   : False
Size        :
Hidden      : False
Name        : d:boot.txt
Readable    : True
System File :
Version     :
Writeable   : True

The above query returns all files on all drives with teh "filename" "boot". If I add teh extension like this:

PS> Get-WmiObject -Query "SELECT * FROM cim_datafile where filename='boot' AND Extension='ini'"

We will get only files with an ini extension from all local drives. This will return only two file objects from the above example.

This will allow searching for a file by name on all installed drives but will take a long time due to the need to scan all files on all drives. Adding teh path will restrict this so it will be much faster.

PS> Get-WmiObject -Query "SELECT * FROM cim_datafile where filename='boot' AND Extension='ini' AND Path='fold1fold2'"

Will find only a file in that path on all drives.
User avatar
donj
Posts: 416
Last visit: Thu May 29, 2008 5:08 am

computer asset inventory

Post by donj »

I am going to stress this very heavily Dee.  You really need to get a book or take a class in PowerShell.  YOu are asing questions about each lin eof code.  Many of these questions you are very close to having an answer for but it appears you lack some of the fundamentals.  Save yourseld some frustration and get one of the many books on programming PowerShell.
Not frustrated here. But, it seems like you are frustrated with me. Sorry I won't bother you again. Maybe others might be willing to assistant on this site.

If you don't want to help don't and you don't need to insult me and say I lack the fundamentals and need formal training. I am new to powershell. I don't see anywhere on this site saying you can't ask newbie questions.. how-TOs, etc. If you are not interested then just don't answer.
Okay - let me reiterate the policy on this Web site. If you see a question you don't want to answer, then DON'T ANSWER IT. However, if you choose to answer - then ANSWER. If you'd like to politely suggest that a particular book might be helpful, then please do so - suggest a PARTICULAR book. However, please ensure that you're not coming across as insulting. People come here for help, not a brush-off.

Dee, please consider that some folks have a harder time expressing themselves in writing. What they write as a polite suggestion can come across as a brush-off to someone else.
User avatar
dee
Posts: 35
Last visit: Wed May 21, 2008 8:36 am

computer asset inventory

Post by dee »

I figured it out on how to use the ConvertToDateTime....

Code: Select all

Get-WmiObject -Query "SELECT * FROM cim_datafile where name='c:program filesesetupdfileslastupd.ver'" -ComputerName $_ -Credential $cred |
	Select-Object Name,@{Name="LastModified";Expression={$_.ConvertToDateTime($_.LastModified)}} | Format-List
Now instead of showing "LastModified : 20080428114231.585250-300" it shows "LastModified : 4/28/2008 12:42:34 PM instead. Just the way I want it. I'm proud of myself. LOL! ;)
User avatar
dee
Posts: 35
Last visit: Wed May 21, 2008 8:36 am

computer asset inventory

Post by dee »

No problem. I've learned allot from you and scriptinganswers.com's posts. Good Job! I've come a long way since my 1st post on here, so i'm greatly appreciative of all you do here.

Thanks,
dee
deepakm@rice.edu dee2008-04-28 11:13:00
User avatar
dee
Posts: 35
Last visit: Wed May 21, 2008 8:36 am

computer asset inventory

Post by dee »

thanks. yeah i have the book.. ;)
User avatar
davidjhodson
Posts: 1
Last visit: Tue May 06, 2008 5:19 am

computer asset inventory

Post by davidjhodson »

On that note you can actually pull driver info from the Win32_PnPSignedDriver class.

example script written by someone smarter than me, but customize for our NICs at work (intel NICs):

Foreach ($strComputer in get-content C:scriptscomplist.txt){$PnP = Get-WMIObject Win32_PnPSignedDriver -computer $strcomputer |where {$_.Devicename -like "Intel(R) 82566DM*"}$strComputerforeach ($Nic in $PnP){"NetWork Adapter Name: $($Nic.Devicename)""Network Adapter Driver Version: $($Nic.DriverVersion)"}}

This is all assuming you have standardized hardware, meaning all servers have the same type of NIC.

You can then modify the script as you see fit to get other driver info, it just filters by devicename.

though I haven't dug through all 7 pages, so I hope I'm not sounding redundant.

Sorry, sample output from running the script:

05/06/2008 10:52:11 C:Usersa-davhodDesktop > .nic_driver_test.ps1a-davhodNetWork Adapter Name: Intel(R) 82566DM Gigabit Network ConnectionNetwork Adapter Driver Version: 9.10.8.0
User avatar
jsclmedave
Posts: 11
Last visit: Tue Jul 22, 2008 5:52 am

computer asset inventory

Post by jsclmedave »

Somewhat on the same topic. I am actually going to take the bit about the credentials and apply it to this. Hope it helps...

Tim Bolton



Function GetDriveSpace { #Retrieve Drive Space on Remote Computers
#SET TARGET SERVERS$servers = "ServerName", "ServerName"
foreach ($target in $servers){
write-output " "$Target$obj = (gwmi -query "select * from win32_logicaldisk where Size > 1" -computername $target -cred $pw)foreach ($disk in $obj) {$freespace = ($disk.freespace / 1gb)$totalspace = ($disk.Size / 1gb)$freepercent = (($freespace / $totalspace)*100)if ($freepercent -lt "15") {$Drive = "Drive " + $disk.deviceid + " has " + ($disk.freespace / 1gb).ToString("n") + "GB Free of " + ($disk.Size / 1gb).ToString("n") + "GB." + $freepercent.ToString("n") + "% Free."$Drive }else {$Drive = "Drive " + $disk.deviceid + " has " + ($disk.freespace / 1gb).ToString("n") + "GB Free of " + ($disk.Size / 1gb).ToString("n") + "GB." + $freepercent.ToString("n") + "% Free."$Drive }}}}
GetDriveSpace >> C:test.csv

User avatar
dee
Posts: 35
Last visit: Wed May 21, 2008 8:36 am

computer asset inventory

Post by dee »

Know of a way to retrieve the scheduled tasks runas logon account of remote servers? I tried via the Win32_ScheduleJob, but it looks like it only works if it was created via AT. Otherwise it shows blank. Any ideas? Thank you so much for all your help!
Dee
This topic is 15 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked