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 - Newbie: WMI and Powershell

Reply
 
Old 10-11-2007   #1 (permalink)
Jeff


 
 

Newbie: WMI and Powershell

I am running the following command from the powershell command line:

PS C:\Users\jpoling> Get-Content c:\scripts\servers.txt | Foreach-Object
{Get-Wmiobject -credential $admin -computername $_ -query "SELECT CSName,
Caption, CSDVersion from win32_operatingsystem"}|out-file c:\temp\test.txt

PArt of the output includes the following:

__GENUS : 2
__CLASS : Win32_OperatingSystem
__SUPERCLASS :
__DYNASTY :
__RELPATH :
__PROPERTY_COUNT : 3
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :

Is there a way to structure the WMI query so that i do not get the above,
but only the three properties I want?

Any advice for a rookie is greatly appreciated.

jeff


My System SpecsSystem Spec
Old 10-11-2007   #2 (permalink)
Brandon Shell [MVP]


 
 

Re: Newbie: WMI and Powershell

Perhaps this

:\Users\jpoling> Get-Content c:\scripts\servers.txt | Foreach-Object {Get-Wmiobject
-credential $admin -computername $_ -query "SELECT * from win32_operatingsystem"}
| Select CSName,Caption,CSDVersion | out-file c:\temp\test.txt


Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

J> I am running the following command from the powershell command line:
J>
J> PS C:\Users\jpoling> Get-Content c:\scripts\servers.txt |
J> Foreach-Object {Get-Wmiobject -credential $admin -computername $_
J> -query "SELECT CSName, Caption, CSDVersion from
J> win32_operatingsystem"}|out-file c:\temp\test.txt
J>
J> PArt of the output includes the following:
J>
J> __GENUS : 2
J> __CLASS : Win32_OperatingSystem
J> __SUPERCLASS :
J> __DYNASTY :
J> __RELPATH :
J> __PROPERTY_COUNT : 3
J> __DERIVATION : {}
J> __SERVER :
J> __NAMESPACE :
J> __PATH :
J> Is there a way to structure the WMI query so that i do not get the
J> above, but only the three properties I want?
J>
J> Any advice for a rookie is greatly appreciated.
J>
J> jeff
J>


My System SpecsSystem Spec
Old 10-11-2007   #3 (permalink)
Jeff


 
 

Re: Newbie: WMI and Powershell

> :\Users\jpoling> Get-Content c:\scripts\servers.txt | Foreach-Object
Quote:

> {Get-Wmiobject -credential $admin -computername $_ -query "SELECT * from
> win32_operatingsystem"} | Select CSName,Caption,CSDVersion | out-file
> c:\temp\test.txt
Thank you! That did exactly what I wanted

Jeff

My System SpecsSystem Spec
Old 10-11-2007   #4 (permalink)
Brandon Shell [MVP]


 
 

Re: Newbie: WMI and Powershell

Im glad it helped.

For more info on Select-object
PS> Get-Help Select-Object -full


I should note, Select-object does change the type of the object so its not
always the answer.

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject
Quote:
Quote:

>> :\Users\jpoling> Get-Content c:\scripts\servers.txt | Foreach-Object
>> {Get-Wmiobject -credential $admin -computername $_ -query "SELECT *
>> from win32_operatingsystem"} | Select CSName,Caption,CSDVersion |
>> out-file c:\temp\test.txt
>>
J> Thank you! That did exactly what I wanted
J>
J> Jeff
J>


My System SpecsSystem Spec
Old 10-11-2007   #5 (permalink)
Kuma


 
 

Re: Newbie: WMI and Powershell

On Oct 11, 11:34 pm, "Jeff" <jeffpol...@xxxxxx> wrote:
Quote:

> I am running the following command from the powershell command line:
>
> PS C:\Users\jpoling> Get-Content c:\scripts\servers.txt | Foreach-Object
> {Get-Wmiobject -credential $admin -computername $_ -query "SELECT CSName,
> Caption, CSDVersion from win32_operatingsystem"}|out-file c:\temp\test.txt
>
> PArt of the output includes the following:
>
> __GENUS : 2
> __CLASS : Win32_OperatingSystem
> __SUPERCLASS :
> __DYNASTY :
> __RELPATH :
> __PROPERTY_COUNT : 3
> __DERIVATION : {}
> __SERVER :
> __NAMESPACE :
> __PATH :
>
> Is there a way to structure the WMI query so that i do not get the above,
> but only the three properties I want?
>
> Any advice for a rookie is greatly appreciated.
>
> jeff
Hey Jeff,
Try this one. I use Select-Object to grab just the properties i want.

Get-Content c:\scripts\servers.txt | Foreach-Object{Get-Wmiobject -
credential $admin -computername $_ -query {SELECT * from
win32_operatingsystem} | select-object CSName,Caption,CSDersion} | out-
file c:\temp\test.txt


Regards,
Kuma

My System SpecsSystem Spec
Old 10-11-2007   #6 (permalink)
Jeff


 
 

Re: Newbie: WMI and Powershell

> Hey Jeff,
Quote:

> Try this one. I use Select-Object to grab just the properties i want.
>
> Get-Content c:\scripts\servers.txt | Foreach-Object{Get-Wmiobject -
> credential $admin -computername $_ -query {SELECT * from
> win32_operatingsystem} | select-object CSName,Caption,CSDersion} | out-
> file c:\temp\test.txt
Thanks! Brandon suggested the same method and it works very well in my case.
I appreciate the advice!

Jeff

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Powershell Newbie PowerShell
powershell newbie help PowerShell
Newbie to Powershell PowerShell
Newbie to PowerShell PowerShell
newbie - How to use FTP in powershell 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