I have a SQL Agent job with 3 separate Operating System Command Steps.
PowerShell.exe Get-Date PowerShell.exe Get-Counter "\\mmserver\Memory\Pages/sec" | Format-table -auto PowerShell.exe Get-Counter "\\myserver\Memory\Available MBytes" | Format-Table -auto
The first two steps work fine. The third fails. I have tried reformatting the counter name in any number of ways including escaping the backslashes, adding single quotes around various pieces, and I tried creating a string variable for the counter name.
The failure message varies a little depending on what I change but basically it seems to be trying to interpret "MBytes" as a separate parameter. For example:
The error information returned by PowerShell is: 'Get-Counter : A positional parameter cannot be found that accepts argument 'MBy '
Followed immediately in the log file with a second error on the remainder of the command string.
The error information returned by PowerShell is: 'tes'. At line:1 char:12 + Get-Counter <<<< \\myserver\Memory\Available MBytes + CategoryInfo : InvalidArgument: (:) [Get-Counter], ParameterBindingException '
Other errors indicate the name of the counter is wrong in someway. For example, I found I had to include the server name even though the script is running locally and it works find from the ISE.
I appreciate any assistance :)
Ray