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 »

I did that and still i get several prompts for each section for a server...

Code: Select all

$cred = Get-Credential (elvez)
	Function Get-Info {
	PROCESS {
	#
	
	"----------------------------------------------------------"
	" Computer Information"
	"----------------------------------------------------------"
	get-wmiobject -query "SELECT * FROM Win32_ComputerSystem" -ComputerName $_ -Credential $cred |
	select-object Name,Domain,Description,Manufacturer,Model,NumberOfProcessors,`
	TotalPhysicalMemory,SystemType,PrimaryOwnerName,UserName
	
	"----------------------------------------------------------"
	" BIOS Information"
	"----------------------------------------------------------"
	get-wmiobject -query "SELECT * FROM Win32_BIOS" -ComputerName $_ -Credential $cred |
	select-object Name,Version,SMBIOSBIOSVersion
	
	"----------------------------------------------------------"
	" CPU Information"
	"----------------------------------------------------------"
	get-wmiobject -query "SELECT * FROM Win32_Processor" -ComputerName $_ -Credential $cred |
	select-object Manufacturer,Name,CurrentClockSpeed,L2CacheSize
	
	"----------------------------------------------------------"
	" Operating System Information"
	"----------------------------------------------------------"
	get-wmiobject -query "SELECT * FROM Win32_OperatingSystem" -ComputerName $_ -Credential $cred | 
	select-object Caption,BuildNumber,Version,SerialNumber,ServicePackMajorVersion,InstallDate
	
	"----------------------------------------------------------"
	" Name of Built-In Administrator Account (Even If Renamed)"
	"----------------------------------------------------------"
	get-wmiobject -query "SELECT * FROM Win32_UserAccount" -ComputerName $_ -Credential $cred |
	where-object {$_SID -match '-500$'} | 
	select-object Name
	
	"----------------------------------------------------------"
	" Installed Hotfixes"
	"----------------------------------------------------------"
	get-wmiobject -query "SELECT * FROM Win32_QuickFixEngineering" -ComputerName $_ -Credential $cred |
	select-object HotFixID
	}
	}
	Get-Content c:serverlist.txt | Get-Info
User avatar
dee
Posts: 35
Last visit: Wed May 21, 2008 8:36 am

computer asset inventory

Post by dee »

that # should be there, correct? and what does that # do?
User avatar
donj
Posts: 416
Last visit: Thu May 29, 2008 5:08 am

computer asset inventory

Post by donj »

Are you running this in *PowerShell itself* and not a third-party utility?
User avatar
dee
Posts: 35
Last visit: Wed May 21, 2008 8:36 am

computer asset inventory

Post by dee »

i'm writing it with PowerGUI Script Editor and running it with PowerShellV2
User avatar
dee
Posts: 35
Last visit: Wed May 21, 2008 8:36 am

computer asset inventory

Post by dee »

ok now it is working. interesting though. if i hit cancel it still proceeds.. is it because the account that i'm logged in with on the PC has admin rights to the domain? i'm thinking yes...

but, it's working now to just one prompt once it is entered....
User avatar
donj
Posts: 416
Last visit: Thu May 29, 2008 5:08 am

computer asset inventory

Post by donj »

The BEGIN block is the preferred way, at least until v2 when script cmdlets support actual parameters.

However, setting $cred outside the function, prior to the function running, should also work. With $cred not existing inside the function, PowerShell will go to the parent scope (the script, where $cred is defined) to find it. Jvierra's solution is a *better* one because it keeps the function entirely self-contained.
User avatar
dee
Posts: 35
Last visit: Wed May 21, 2008 8:36 am

computer asset inventory

Post by dee »

Thank you! This worked like a charm. I'm learning. Another question.... what Win32 object provides network information and software installed? Also, i'm trying to obtain the Dell server tag. Any ideas? Thank you so much!

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

computer asset inventory

Post by dee »

Thanks. Know of a good source that has a dictionary of all the classes and attributes that can be used with wmiObject?

Also, what should I add to export the results to either a .txt or .doc? I can do it via something.ps1 > test.txt

Thanks again for all your help!

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

computer asset inventory

Post by dee »

the Get-Help is pretty cool.. thought there might be a more friendly resource. thanks!

dee
User avatar
donj
Posts: 416
Last visit: Thu May 29, 2008 5:08 am

computer asset inventory

Post by donj »

BTW, as for a more friendly resource... www.sapienpress.com/powershell2.asp. :) Highly recommended, at least by me. We have some online training coming up, too - go to the Training Zone on this site and select online training. Pretty affordable, if you're interested.donj2008-03-14 13:16:32
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