Q: invoke-command get-counter ... possible?

Hi again,

using the get-counter cmdlet to gather data from machines seems somewhat cumbersome.

I tryied to use the invoke-command cmdlet in combination with get-counter to have the remote machines do the job.

The question is now: How can I aggragate the data the remote machines produce.

When using get-counter without invoke-command I can add an export-counter cmdlet which writes all data in one nice .blg file. With invoke-command I did not get this to work.



Can you provide a small example of what isn’t working?

Hi Don,

this is what I’m trying to execute:

invoke-command -ComputerName REMOTECOMPUTER {get-counter -counter “\logicaldisk(_total)\Disk Transfers/Sec” -SampleInterval 3 -Continuous| Export-counter -force -Path \MYCOMPUTER\temp\myoutput.blg}

I get an Error:

Unable to create the \MYCOMPUTER\temp\myoutput.blg file. Verify that the path is valid.
+ CategoryInfo : InvalidResult: (:slight_smile: [Export-Counter], Exception
+ FullyQualifiedErrorId : FileCreateFailed,Microsoft.PowerShell.Commands.ExportCounterCommand

I checked for permissions. I can access the share \MYCOMPUTER\temp from another server box when logged in to Windows without having to authenticate explicit.

share permission is set to “Everyone” R/W
Security is set to “Everyone” Full control

I tested with test-path and resolve-path as well from a remote box:

PS C:\Users\myuserpath> resolve-path \MYCOMPUTER\temp



PS C:\Users\myuserpath> test-path \MYCOMPUTER\temp

Did I miss something here?



…I just PS remoted to the REMOTECOMPUTER from my box. When I test it from there I get the following:

PS C:\Windows\system32> Enter-PSSession REMOTECOMPUTER
[REMOTECOMPUTER]: PS C:\Users\myuserpath\Documents> test-path \MYCOMPUTER\temp
test-path : Access is denied
+ CategoryInfo : PermissionDenied: (\MYCOMPUTER\temp:String) [Test-Path], UnauthorizedAccessException
+ FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.TestPathCommand

[REMOTECOMPUTER]: PS C:\Users\myuserpath\Documents> resolve-path \MYCOMPUTER\temp
resolve-path : Access is denied
+ CategoryInfo : PermissionDenied: (\MYCOMPUTER\temp:String) [Resolve-Path], UnauthorizedAccessException
+ FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.ResolvePathCommand

resolve-path : Cannot find path ‘\MYCOMPUTER\temp’ because it does not exist.
+ CategoryInfo : ObjectNotFound: (\MYCOMPUTER\temp:String) [Resolve-Path], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand

Test-path and resolve-path from a Windows Server 2008 R2 box to my Windows 7 share works.
Test-path and resolve-path from a Windows 7 box to my own Windows 7 share does not work.

Same user account is beeing used. Same domain.



The problem is most likely authentication. By default, the computer you’ve remoted to cannot use your credential to access non-local resources like a UNC. This is referred to as the “second hop” problem, and is discussed in “Secrets of PowerShell Remoting,” one of our free ebooks (Resources menu here on the site).

Already reading it… thanks Don.