none
How to run Get-Counter Powershell on the command line? RRS feed

  • Question

  • Hello,

    Get-Counter "\Hyper-V VM VID Partition(*)\*"    ==> This works fine in a Power Shell window

    PowerShell Get-Counter                                     ==> This works fine in a command window

    PowerShell Get-Counter "\Hyper-V VM VID Partition(*)\*"     ==> This fails in cmd window complains about the star inside the braces

    PowerShell -Command "& {Get-Counter "\Hyper-V VM VID Partition(*)\*"}"  ==> Fails in command window same way

    Between the last two formats of running PowerShell commands in a command window I have tried all possible combination escape, quotes, braces what ever I do it fails. Please help me. (*) that is the culprit

    Thanks a lot in advance

    ananda


    Friday, August 9, 2019 12:33 AM

Answers

  • Hi,

    Thanks for your question.

    If the command to be executed has quotes, they must be doubled. Example : powershell -command "dir ""c:\Program Files""". Or  you can just use single quotes powershell -command " dir 'C:\Program Files' ".

    Please try to use the command below:

    PowerShell -command "Get-Counter '\Hyper-V VM VID Partition(*)\*' "

    Best regards,

    Lee



    Just do it.


    Friday, August 9, 2019 2:05 AM
    Moderator

All replies

  • Hi,

    Thanks for your question.

    If the command to be executed has quotes, they must be doubled. Example : powershell -command "dir ""c:\Program Files""". Or  you can just use single quotes powershell -command " dir 'C:\Program Files' ".

    Please try to use the command below:

    PowerShell -command "Get-Counter '\Hyper-V VM VID Partition(*)\*' "

    Best regards,

    Lee



    Just do it.


    Friday, August 9, 2019 2:05 AM
    Moderator
  • You can also do it like this to avoid quoting issues.

    PowerShell {Get-Counter "\Hyper-V VM VID Partition(*)\*"}


    \_(ツ)_/


    Friday, August 9, 2019 3:30 AM
    Moderator
  • This did not work but the other one did work. When I did this, this is what I got:

    C:\tmp>PowerShell {Get-Counter "\Hyper-V VM VID Partition(*)\*"}
    Get-Counter \Hyper-V VM VID Partition(*)\*

    It just echoed the command no other output. However dont worry the problem is soled thanks to @LeeSeenLi

    Friday, August 9, 2019 5:51 AM
  • This did not work but the other one did work. When I did this, this is what I got:

    C:\tmp>PowerShell {Get-Counter "\Hyper-V VM VID Partition(*)\*"}
    Get-Counter \Hyper-V VM VID Partition(*)\*

    It just echoed the command no other output. However dont worry the problem is soled thanks to @LeeSeenLi

    This only works on a command line (PowerShell command line).  This is a PowerShell forum therefore your question is about the PowerShell command line. 

    \_(ツ)_/


    Friday, August 9, 2019 6:26 AM
    Moderator