locked
A question about Test-Path RRS feed

  • Question

  • Hello

    If I am logged in as a user with enough rights and I do this (I have replaced he real path with \\Server\Path)

    Test-Path \\Server\Path

    or

    Test-Path FileSystem::\\Server\Path

    That works OK

    If I am logged in a a user with normal rights and I try the following

    $Cred = Get-Creidential

    e.g. store the credentials of a domain admin user (as above in the first test)

    Test-Path Test-Path \\Server\Path -Creidential $Cred

    I get the following error

    Test-Path : Cannot retrieve the dynamic parameters for the cmdlet. The FileSystem provider supports credentials only on the New-PSDrive cmdlet. Perform the operation again without specifying
    credentials.
    At line:1 char:1
    + Test-Path \\Server\Path -Credential $cred
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Test-Path], ParameterBindingException
        + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.TestPathCommand

    if I try this

    invoke-command {Test-Path \\Server\Path } -Credential $Cred

    I get the following error

    Invoke-Command : Parameter set cannot be resolved using the specified named parameters.
    At line:1 char:1
    + Invoke-Command {test-path \\Server\Path } -Credential $cred
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Invoke-Command], ParameterBindingException
        + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand

    the Test-Path cmdlet has a -credential parameter, but I cannot seem to use it, any ideas please

    I am using PowerShell v4

    Thank you

    AAnotherUser__


    AAnotherUser__

    Wednesday, June 4, 2014 11:58 AM

Answers

  • Hi AanotherUser__

    as the official documentation for Test-Path describes for the parameter Credential:

    "This parameter is not supported by any providers installed with Windows PowerShell."

    This parameter has been included to support third-party providers that implement Credential support for Test-Path. Ergo: You can't use it like this.
    You might be able to circumvent this limitation by using Invoke-Command.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Proposed as answer by jrv Wednesday, June 4, 2014 1:12 PM
    • Marked as answer by AAnotherUser Thursday, June 5, 2014 9:41 AM
    Wednesday, June 4, 2014 12:28 PM

All replies

  • Hi AanotherUser__

    as the official documentation for Test-Path describes for the parameter Credential:

    "This parameter is not supported by any providers installed with Windows PowerShell."

    This parameter has been included to support third-party providers that implement Credential support for Test-Path. Ergo: You can't use it like this.
    You might be able to circumvent this limitation by using Invoke-Command.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Proposed as answer by jrv Wednesday, June 4, 2014 1:12 PM
    • Marked as answer by AAnotherUser Thursday, June 5, 2014 9:41 AM
    Wednesday, June 4, 2014 12:28 PM
  • Thanks for the clarification Fred :)

    AAnotherUser__


    AAnotherUser__

    Thursday, June 5, 2014 9:41 AM