How do I use -Credential parameter?



There are some buildin cmdlets with -Credential parameter (for example
those *-Item cmdlet). But when I used those cmdlet with -Credential, I
always got an error (no matter it is Filesystem provider or registry
provider).

Is there something I did wrong or Is it designed to act like that?

=======================================================
C:\WINDOWS> new-item . -Name my.txt -type "file"
new-item : Access to the path 'C:\WINDOWS\my.txt' is denied.
At line:1 char:9
+ new-item <<<< . -Name my.txt -type "file"
=======================================================
C:\WINDOWS> new-item . -Name my.txt -type "file" -Credential Admin

Credential Information
Please enter your credentials.
Password for user Admin: ******

new-item : Dynamic parameters for the Cmdlet cannot be retrieved.
Invocation of
MakePath on the 'FileSystem' provider failed for path 'C:\'. Cannot
call metho
d. The provider does not support the use of credentials.
At line:1 char:9
+ new-item <<<< . -Name my.txt -type "file" -Credential Admin
=======================================================
C:\WINDOWS> $me=get-credential

Cmdlet get-credential at command pipeline position 1
Supply values for the following parameters:
Credential
User: Admin
Password for user Admin: ******

C:\WINDOWS> new-item . -Name my.txt -type "file" -Credential $me
new-item : Dynamic parameters for the Cmdlet cannot be retrieved.
Invocation of
MakePath on the 'FileSystem' provider failed for path 'C:\'. Cannot
call metho
d. The provider does not support the use of credentials.
At line:1 char:9
+ new-item <<<< . -Name my.txt -type "file" -Credential $me
=========================================================

.



Relevant Pages

  • Re: How do I use -Credential parameter?
    ... FileSystem and Registry provider do not supprt Credential parameter for V1. ... But when I used those cmdlet with -Credential, ... The provider does not support the use of credentials. ...
    (microsoft.public.windows.server.scripting)
  • Re: [MSH]about cmdlets hidden parameters question
    ... The provider cmdlets like get-childitem using the ... parameters for the cmdlet. ... {Path, Filter, Include, Exclude, Recurse, Force, Verbose, ... (get-command get-content).parametersets" ...
    (microsoft.public.windows.server.scripting)
  • RE: CredentialAttribute
    ... but let's concentrate on the get-credential cmdlet. ... i though that the cmdlet would automatically show the dialog to get the credentials from the user. ...
    (microsoft.public.windows.server.scripting)
  • Re: CredentialAttribute
    ... MshCredential object to a parameter. ... but let's concentrate on the get-credential cmdlet. ... the cmdlet would automatically show the dialog to get the credentials from ...
    (microsoft.public.windows.server.scripting)