Posted by: Preetam | January 17, 2007

Computer Inventry with Powershell

I’m planning to put here series of code to get the computer inventory of machines. As you could remember last time I got the IP Address of the machine. This time I wanna know how many and what programs are installed on this machine.

$ALLPROGS=Get-ChildItem “hklm:\software\microsoft\windows\currentversion\uninstall” ForEach-Object {Get-ItemProperty $_.pspath}
if ($args -eq “sort” )

{
$ALLPROGS Select-Object displayname,publisher sort publisher

}
else

{

$ALLPROGS Select-Object displayname,publisher group publisher sort count

}

I’ve purposely left this code hanging whether you wish to have group programs or sort by name of the application publisher. Program is simple but fact that I would like to mentioned here, I tried the other way round, which I’ve pasted just for the sake of not to do do this.

USAGE: .\AllPrograms02.ps1 sort or .\AllPrograms02.ps1

$ALLPROG=”hklm:\Software\Microsoft\Windows\CurrentVersion\Uninstall”
$CHILDPROG=get-childitem $ALLPROG
$PROGNAME=$CHILDPROG select-object pschildname
for($i=0;$i -lt $PROGNAME.length; $i++) {
$EACHPROG=$PROGNAME[$i].pschildname
$PROGS=”hklm:\Software\Microsoft\Windows\CurrentVersion\Uninstall\$EACHPROG”
$PROGS get-itemproperty select-object displayname,publisher sort displayname
}

Even though I have mentioned sort by displayname it won’t work, sorting fails here because it has to be with POST here…

http://blogs.msdn.com/powershell/archive/2007/01/11/sorting-out-groupby.aspx, just though of keeping it in my mind. Please bear in mind this is not going to work on remote computer, But for me it doesn’t matter. Because I’m going to run this everytime I built the server or someone asks me or Best one is to do by using psexec..hahaha. But certainly in future there is would be simpler way to run this across enterprise.

Technorati tags:

del.icio.us tags:

IceRocket tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: