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 question

Reply
 
Old 09-08-2007   #1 (permalink)
JasonJFT


 
 

Newbie question

This works ok if I run this directly from a ps prompt but I get an
error when I try to pass it to powershell.exe. What am I doing wrong?

C:\....v1.0>powershell.exe "(get-wmiobject
Win32_PerfFormattedData_PerfProc_Process -filter "name =
'sqlservr'").PercentProcessorTime"
Get-WmiObject : A parameter cannot be found that matches parameter
name 'sqlservr'.
At line:1 char:15
+ (get-wmiobject <<<< Win32_PerfFormattedData_PerfProc_Process -
filter name = 'sqlservr').PercentProcessorTime


My System SpecsSystem Spec
Old 09-08-2007   #2 (permalink)
Shay Levi


 
 

Re: Newbie question

The quotes hell . Here's a workaround. It works when typed into CMD.exe


powershell.exe "(get-wmiobject Win32_PerfFormattedData_PerfProc_Process -filter
"""name ='sqlservr'""").PercentProcessorTime"

-or-

powershell.exe -command "(get-wmiobject Win32_PerfFormattedData_PerfProc_Process
-filter """name ='sqlservr'""").PercentProcessorTime"



Shay
http://scriptolog.blogspot.com


Quote:

> This works ok if I run this directly from a ps prompt but I get an
> error when I try to pass it to powershell.exe. What am I doing wrong?
>
> C:\....v1.0>powershell.exe "(get-wmiobject
> Win32_PerfFormattedData_PerfProc_Process -filter "name =
> 'sqlservr'").PercentProcessorTime"
> Get-WmiObject : A parameter cannot be found that matches parameter
> name 'sqlservr'.
> At line:1 char:15
> + (get-wmiobject <<<< Win32_PerfFormattedData_PerfProc_Process -
> filter name = 'sqlservr').PercentProcessorTime

My System SpecsSystem Spec
Old 09-08-2007   #3 (permalink)
Shay Levi


 
 

Re: Newbie question

Or escape the inside double quotes

powershell.exe -command "(get-wmiobject Win32_PerfFormattedData_PerfProc_Process
-filter \"name ='sqlservr'\").PercentProcessorTime"


Shay
http://scriptolog.blogspot.com


Quote:

> The quotes hell . Here's a workaround. It works when typed into
> CMD.exe
>
> powershell.exe "(get-wmiobject
> Win32_PerfFormattedData_PerfProc_Process -filter """name
> ='sqlservr'""").PercentProcessorTime"
>
> -or-
>
> powershell.exe -command "(get-wmiobject
> Win32_PerfFormattedData_PerfProc_Process -filter """name
> ='sqlservr'""").PercentProcessorTime"
>
> Shay
> http://scriptolog.blogspot.com
Quote:

>> This works ok if I run this directly from a ps prompt but I get an
>> error when I try to pass it to powershell.exe. What am I doing wrong?
>>
>> C:\....v1.0>powershell.exe "(get-wmiobject
>> Win32_PerfFormattedData_PerfProc_Process -filter "name =
>> 'sqlservr'").PercentProcessorTime"
>> Get-WmiObject : A parameter cannot be found that matches parameter
>> name 'sqlservr'.
>> At line:1 char:15
>> + (get-wmiobject <<<< Win32_PerfFormattedData_PerfProc_Process -
>> filter name = 'sqlservr').PercentProcessorTime

My System SpecsSystem Spec
Old 09-09-2007   #4 (permalink)
JasonJFT


 
 

Re: Newbie question

Thanks Shay. That worked like a champ. I actually had to add more
quotes when I moved it into SQL. I am having more problems with this
one.

PS C:\Windows\System32\WindowsPowerShell\v1.0> (get-wmiobject
Win32_PerfFormattedData_PerfDisk_PhysicalDisk -filter "name =
'c:'").AvgDiskSecPerRead

It is coming back with nothing even if I remove the filter. All google
gets me is vb script samples for this and similar classes.


Is there a good starting place? I guess I need something more basic
than http://www.microsoft.com/technet/scr...mshandwmi.mspx


My System SpecsSystem Spec
Old 09-09-2007   #5 (permalink)
Shay Levi


 
 

Re: Newbie question

Here is a start

(get-wmiobject Win32_PerfFormattedData_PerfDisk_PhysicalDisk -filter "name
like '%c%'").AvgDiskSecPerRead



Shay
http://scriptolog.blogspot.com


Quote:

> Thanks Shay. That worked like a champ. I actually had to add more
> quotes when I moved it into SQL. I am having more problems with this
> one.
>
> PS C:\Windows\System32\WindowsPowerShell\v1.0> (get-wmiobject
> Win32_PerfFormattedData_PerfDisk_PhysicalDisk -filter "name =
> 'c:'").AvgDiskSecPerRead
>
> It is coming back with nothing even if I remove the filter. All google
> gets me is vb script samples for this and similar classes.
>
> Is there a good starting place? I guess I need something more basic
> than
> http://www.microsoft.com/technet/scr.../mshandwmi.msp
> x
>

My System SpecsSystem Spec
Old 09-09-2007   #6 (permalink)
Shay Levi


 
 

Re: Newbie question

BTW, this NG is the best place to start


Shay
http://scriptolog.blogspot.com


Quote:

> Here is a start
>
> (get-wmiobject Win32_PerfFormattedData_PerfDisk_PhysicalDisk -filter
> "name like '%c%'").AvgDiskSecPerRead
>
> Shay
> http://scriptolog.blogspot.com
Quote:

>> Thanks Shay. That worked like a champ. I actually had to add more
>> quotes when I moved it into SQL. I am having more problems with this
>> one.
>>
>> PS C:\Windows\System32\WindowsPowerShell\v1.0> (get-wmiobject
>> Win32_PerfFormattedData_PerfDisk_PhysicalDisk -filter "name =
>> 'c:'").AvgDiskSecPerRead
>>
>> It is coming back with nothing even if I remove the filter. All
>> google gets me is vb script samples for this and similar classes.
>>
>> Is there a good starting place? I guess I need something more basic
>> than
>> http://www.microsoft.com/technet/scr...h/mshandwmi.ms
>> p x
>>

My System SpecsSystem Spec
Old 09-09-2007   #7 (permalink)
JasonJFT


 
 

Re: Newbie question

Here are some simple SQL scripts. Getting this info inside SQL was
relatively difficult before. Thanks again!

insert into @tmp(c1)
exec xp_cmdshell 'powershell.exe -command "(get-wmiobject
Win32_PerfFormattedData_PerfProc_Process -filter """name
=''sqlservr''""").PercentProcessorTime"'

select c1 as cpu from @tmp where c1 is not null


declare @tmp table (c1 int)

insert into @tmp(c1)
exec xp_cmdshell 'powershell.exe -command "(get-wmiobject
Win32_PerfFormattedData_PerfDisk_PhysicalDisk -filter """name
like''%total%''""").AvgDiskSecPertransfer"'

select c1 as AvgDiskSecPertransfer from @tmp where c1 is not null

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
a newbie with a question Virtual PC
Newbie question PowerShell
Newbie question Graphic cards
Just a newbie question General Discussion
RE: Newbie Question 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