Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - Using the $_ pipeline with WMI

Reply
 
Old 04-26-2007   #1 (permalink)
Larry R
Guest


 
 

Using the $_ pipeline with WMI

Newbie here...
I am trying to develop a list of software that needs to be uninstalled
on a computer.

I have the output list :
IdentifyingNumber name vendor
----------------- ---- ------
{01A4AEDE-F219-49A2-B855-16A016EAF9A4} Intel(R) PROSet II Intel


and am trying to iterate through the list and get-wmiobject for each
IdentifyingNumber , then Unintsall.

Here is what I have:
get-content "c:\productsintel.txt" |Get-WmiObject -Class win32_product
-Filter "IdentifyingNumber='$_.IdentifyingNumber'"


1) How do I reference the IdentifyingNumber correctly when reading the
file?
2) is the "filter" syntax correct?

Thanks
Larry


My System SpecsSystem Spec
Old 04-26-2007   #2 (permalink)
/\\/\\o\\/\\/ [MVP]
Guest


 
 

Re: Using the $_ pipeline with WMI

In this case it's better to use a CSV file to provide the software you want
uninstalled as you can import that back as an object

PoSH> $sw = (gwmi win32_product -prop IdentifyingNumber,name,vendor)

PoSH> $sw | select [a-z]* |? {$_.Vendor -eq 'Macromedia'}

IdentifyingNumber Name
Vendor
----------------- ----
------
{91057632-CA70-413C-B628-2D3CDBBB906B} Macromedia Flash Player 8 Plugin
Macromedia


PoSH> $sw | select [a-z]* |? {$_.Vendor -eq 'Macromedia'} | Export-Csv
Macromedia.csv

PoSH> Import-Csv Macromedia.csv |% {gwmi win32_product -filter
"Vendor='$($_.vendor)'"}


IdentifyingNumber : {91057632-CA70-413C-B628-2D3CDBBB906B}
Name : Macromedia Flash Player 8 Plugin
Vendor : Macromedia
Version : 8.0.22.0
Caption : Macromedia Flash Player 8 Plugin

Greetings /\/\o\/\/
http://thePowerShellGuy.Com

"Larry R" <wantitoverwith@gmail.com> wrote in message
news:1177610197.702375.236720@t38g2000prd.googlegroups.com...
> Newbie here...
> I am trying to develop a list of software that needs to be uninstalled
> on a computer.
>
> I have the output list :
> IdentifyingNumber name vendor
> ----------------- ---- ------
> {01A4AEDE-F219-49A2-B855-16A016EAF9A4} Intel(R) PROSet II Intel
>
>
> and am trying to iterate through the list and get-wmiobject for each
> IdentifyingNumber , then Unintsall.
>
> Here is what I have:
> get-content "c:\productsintel.txt" |Get-WmiObject -Class win32_product
> -Filter "IdentifyingNumber='$_.IdentifyingNumber'"
>
>
> 1) How do I reference the IdentifyingNumber correctly when reading the
> file?
> 2) is the "filter" syntax correct?
>
> Thanks
> Larry
>


My System SpecsSystem Spec
Old 04-27-2007   #3 (permalink)
Larry R
Guest


 
 

Re: Using the $_ pipeline with WMI

Ok, so now I have

$fileName = "C:\testUninstall.csv"
Import-csv $fileName |% {gwmi win32_product -filter
"IdentifyingNumber='$($_.IdentifyingNumber)'"}

I was trying to do this:
Import-csv $fileName |% { {gwmi win32_product -filter
"IdentifyingNumber='$($_.IdentifyingNumber)'"}
| foreach( write-host "Uninstalling " $_.name )

but I never get the name.

What is the |% syntax for?

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
credential in the pipeline PowerShell
The pipeline is empty PowerShell
object pipeline? PowerShell
Brackets in the pipeline PowerShell
A pipeline exercise PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46