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.
User avatar
dee
Posts: 35
Joined: Wed Mar 05, 2008 6:17 am

computer asset inventory

Post by dee »

sorry nevermind i figured it out. i need to put the full file location with thanks!

Dee

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

computer asset inventory

Post by dee »

sorry for the long trail again. I am familiar with ./something.ps1 > something.txt cmdlet But, trying have the cmdlet run within the code. browsing google...

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

computer asset inventory

Post by dee »

also, the only think i did prior was remove some of the select-objects and re-arranged the code. The following is the code:

Function Get-Info ( $cred ) {
PROCESS {
"----------------------------------------------------------" " Server Name and Domain" "----------------------------------------------------------" Get-WmiObject -Query "SELECT * FROM Win32_ComputerSystem" -ComputerName $_ -Credential $cred | Select-Object Name,Domain "----------------------------------------------------------" " Asset Tag" "----------------------------------------------------------" get-wmiobject -Query "SELECT * FROM Win32_BIOS" -ComputerName $_ -Credential $cred | select-object SerialNumber "----------------------------------------------------------" " Operating System & Service Pack" "----------------------------------------------------------" get-wmiobject -Query "SELECT * FROM Win32_OperatingSystem" -ComputerName $_ -Credential $cred | select-object Caption,BuildNumber,Version,ServicePackMajorVersion
"----------------------------------------------------------" " DISK INFORMATION" "----------------------------------------------------------" Get-WmiObject -Query "SELECT * FROM Win32_LogicalDisk" -ComputerName $_ -Credential $cred | Select-Object VolumeName,Name,Size,FreeSpace,FileSystem "----------------------------------------------------------" " NETWORKING" "----------------------------------------------------------" Get-WmiObject -Query "SELECT * FROM Win32_NetworkAdapterConfiguration" -ComputerName $_ -Credential $cred | Select-Object DNSHostName,DNSDomain,DNSServerSearchOrder,Description,IPAddress,DefaultIPGateway,IPSubnet,MACAddress
"----------------------------------------------------------" " MAJOR SOFTWARE" "----------------------------------------------------------" Get-WmiObject -Query "SELECT * FROM Win32_Product" -ComputerName $_ -Credential $cred | select-object Name "----------------------------------------------------------" " ANTIVIRUS PROTECTION" "----------------------------------------------------------" Get-WmiObject -Query "SELECT * FROM cim_datafile where name='c:program filesesetnod32.exe'" -ComputerName $_ -Credential $cred | Select-Object Name "----------------------------------------------------------" " WINDOWS SERVICES DISABLED" "----------------------------------------------------------" Get-WmiObject -Query "SELECT * FROM Win32_Service" -ComputerName $_ -Credential $cred | Where {$_.StartMode -eq "Disabled" -and $_.Status -eq "OK"} | Select-Object Name,Status,StartMode,DisplayName }}$mycred = Get-Credential ("useradmin")Get-Content c:serverlist.txt | Get-Info $mycred

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

computer asset inventory

Post by dee »

Thanks. Any way to have it in the start? it was working at one time.... should I put the PoSH first?

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

computer asset inventory

Post by dee »

I have another question. Any way of formating the "FreeSpace" that is in bytes to GB or MB? I tried the following, but the results is just showing blank or just the bytes.

Code: Select all

Get-WMIObject Win32_LogicalDisk | 
	Select-Object VolumeName,Name,Size,FreeSpace,FileSystem | 
	ForEach-Object {[math]::truncate($_.Freepace/1GB)}

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

computer asset inventory

Post by dee »

I tried that but, I don't get the right results:

Code: Select all

Get-WmiObject -Query "SELECT * FROM Win32_LogicalDisk" -ComputerName $_ -Credential $cred |
	Where-Object {$_.drivetype -eq 3} |
	Select-Object VolumeName,Name,Size,FreeSpace,FileSystem |
	$_.FreeSpace/1GB
I tried placing the $_.FreeSpace/1GB in other spots of the above code, but no luck yet... any ideas?

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

computer asset inventory

Post by dee »

Nevermind.. I resolved the issue by doing the following:

Code: Select all

Get-WmiObject -Query "SELECT * FROM Win32_LogicalDisk" -ComputerName $_ -Credential $cred |
	Where-Object {$_.drivetype -eq 3} |
	Select-Object VolumeName,Name,FileSystem,@{Name="Freespace";Expression={$_.FreeSpace/1gb}},@{Name="Size";Expression={$_.Size/1gb}}

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

computer asset inventory

Post by jvierra »

You still need to format the output. The result will show the float equivalent in GB and will be formatted according to the output method selected. YOu will get a Scietific Notation like output when converting that will need to be rounded to the precision you want to display.

This is a prettyt long winded explanation of how and why this works. It has to do with plain old arithmatic, the size of things like GBs and MBs, and the way you wish to dispay these things. When I get some time I will look for a bolg I once saw that explains this very nicely. YOu really should get one of Don's books as he and Jeff do a pretty complete explanation of these issues although I don't htink it's under a single heading.

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

computer asset inventory

Post by dee »

new question:
How do you truncate the following:

LastModified : 20080428114231.585250-300

I would like to have the format be a date format and also to truncate the last 17 digits. I have the following:

Code: Select all

Get-WmiObject -Query "SELECT * FROM cim_datafile where name='c:program filesesetupdfileslastupd.ver'" -ComputerName $_ -Credential $cred |
	Select-Object Name,ModifyDate | Format-List

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

computer asset inventory

Post by dee »

when i put no path it gave no data...

Code: Select all

Get-WmiObject -Query "SELECT * FROM cim_datafile where name='nod32.exe'" -ComputerName $_ -Credential $cred |
	Select-Object Name,Version | Format-List

Locked