Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta.9 - Invoke-Item not accepting Credentials ends in error. #5416

Closed
MaximoTrinidad opened this issue Nov 10, 2017 · 6 comments
Closed

Beta.9 - Invoke-Item not accepting Credentials ends in error. #5416

MaximoTrinidad opened this issue Nov 10, 2017 · 6 comments
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-By Design The reported behavior is by design.

Comments

@MaximoTrinidad
Copy link

MaximoTrinidad commented Nov 10, 2017

I'm building an scenario where I want to use "Invoke-Item" cmdlet with credentials but is not taking it Windows.

Although, I don't expect to use this in Linux, I did try it and gave me the same error message.

Steps to reproduce

Create the following credential object:

## In Windwows
	$MyUserName = "MyAdminName";
	$MyPassword = ConvertTo-SecureString '!myPassword$' -asplaintext -force;
	$MyCredentials2 = new-object -typename System.Management.Automation.PSCredential `
								 -argumentlist $MyUserName, $MyPassword;
	Write-Host "Executing PowerShell Core" -foreground 'yellow';
	Invoke-Item 'notepad.exe' -Credential $MyCredentials2;

Try it in Linux (Ubuntu 16.04)

	$MyUserName = "MyAdminName";
	$MyPassword = ConvertTo-SecureString '!myPassword$' -asplaintext -force;
	$MyCredentials2 = new-object -typename System.Management.Automation.PSCredential `
								 -argumentlist $MyUserName, $MyPassword;
	Write-Host "Executing PowerShell Core" -foreground 'yellow';
	Invoke-Item 'gedit' -Credential $MyCredentials2;

Expected behavior

It will open the application with the credential provided.


Actual behavior

Using PowerShell Core and Windows PowerShell in both OS's (Windows and Linux)
getting the following error messsage:

PowerShell v6.0.0-beta.9
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Program Files\PowerShell\6.0.0-beta.9> $MyUserName = "max_t";
PS C:\Program Files\PowerShell\6.0.0-beta.9> $MyPassword = ConvertTo-SecureString 'xxxxxx' -asplaintext -force;
PS C:\Program Files\PowerShell\6.0.0-beta.9> $MyCredentials2 = new-object -typename System.Management.Automation.PSCrede
ntial `
>>  -argumentlist $MyUserName, $MyPassword;
PS C:\Program Files\PowerShell\6.0.0-beta.9> Write-Host "Executing PowerShell Core" -foreground 'yellow';
Executing PowerShell Core
PS C:\Program Files\PowerShell\6.0.0-beta.9> Invoke-Item 'notepad.exe' -Credential $MyCredentials2;
The FileSystem provider supports credentials only on the New-PSDrive cmdlet. Perform the operation again without
specifying credentials.
At line:1 char:1
+ Invoke-Item 'notepad.exe' -Credential $MyCredentials2;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotImplemented: (:) [], PSNotSupportedException
    + FullyQualifiedErrorId : NotSupported

In Linux

PS /home/maxt> $MyUserName = "maxt";                                            
PS /home/maxt> $MyPassword = ConvertTo-SecureString 'xxxxxxxxx' -asplaintext -force;                                                                         
PS /home/maxt> $MyCredentials2 = new-object -typename System.Management.Automation.PSCredential `                                                               >>  -argumentlist $MyUserName, $MyPassword;                                     
PS /home/maxt> 
PS /home/maxt> invoke-item 'gedit' -Credential $MyCredentials2;                 
The FileSystem provider supports credentials only on the New-PSDrive cmdlet. 
Perform the operation again without specifying credentials.
At line:1 char:1
+ invoke-item 'gedit' -Credential $MyCredentials2;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotImplemented: (:) [], PSNotSupportedException
    + FullyQualifiedErrorId : NotSupported
 
PS /home/maxt> 

Environment data

Windows 10 Insider Build 17035
Ubuntu 16.04.3

PS /home/maxt> $PSVersionTable                                                  

Name                           Value                                           
----                           -----                                           
PSVersion                      6.0.0-beta.9                                    
PSEdition                      Core                                            
GitCommitId                    v6.0.0-beta.9                                   
OS                             Linux 4.10.0-38-generic #42~16.04.1-Ubuntu SM...
Platform                       Unix                                            
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                         
PSRemotingProtocolVersion      2.3                                             
SerializationVersion           1.1.0.1                                         
WSManStackVersion              3.0  
PS C:\Program Files\PowerShell\6.0.0-beta.9> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-beta.9
PSEdition                      Core
GitCommitId                    v6.0.0-beta.9
OS                             Microsoft Windows 10.0.17035
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

ii_01_2017-11-10_17-23-53

ii_02_2017-11-10_17-23-53

@MaximoTrinidad
Copy link
Author

MaximoTrinidad commented Nov 10, 2017

FYI - It's happening in all versions of PowerShell
Windows PowerShell - Windows 10 Insider Build 17035

	$MyUserName = "max_t";
	$MyPassword = ConvertTo-SecureString 'xxxxxxx' -asplaintext -force;
	$MyCredentials2 = new-object -typename System.Management.Automation.PSCredential `
								 -argumentlist $MyUserName, $MyPassword;
         Invoke-Item 'notepad.exe' -Credential $MyCredentials2;
PS C:\Users\max_t> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17035.1000
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17035.1000
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

ii_03_2017-11-10_17-23-53

@MaximoTrinidad
Copy link
Author

I will write up the issue in UserVoice for the Windows PowerShell.
:)

@markekraus
Copy link
Contributor

markekraus commented Nov 10, 2017

@MaximoTrinidad

This is the documented behavior https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/invoke-item?view=powershell-5.1

From the -Credential parameter description:

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

The FileSystem PSProvider you are using Invoke-Item on to run a file is one of the providers installed with PowerShell. This parameter is provided for use with custom PSProviders which may require credentials to perform actions such as Invoke-Item

@markekraus markekraus added Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-By Design The reported behavior is by design. labels Nov 10, 2017
@MaximoTrinidad
Copy link
Author

@markekraus,

Hum! You're eager to close this incident and provide a link (which I already have previously checked) without providing any room for a brief discussion.

This is a vague note!

Invoke-Item
Parameter
:
-Credential
:
This parameter is not supported by any providers installed with Windows PowerShell."
:

As, I'm trying to use the Invoke-Item cmdlet, to open either an app or a file which suppose to let use the credential parameter to accomplished my task. And, getting the same error:

PS C:\Users\max_t> ii 'c:\Windows\System32\notepad.exe' -Credential
Invoke-Item : Missing an argument for parameter 'Credential'. Specify a parameter of type
'System.Management.Automation.PSCredential' and try again.
At line:1 char:38
+ ii 'c:\Windows\System32\notepad.exe' -Credential
+                                      ~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-Item], ParameterBindingException
    + FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.InvokeItemCommand

PS C:\Users\max_t> ii 'c:\Windows\System32\drivers\etc\hosts' -credential
Invoke-Item : Missing an argument for parameter 'Credential'. Specify a parameter of type
'System.Management.Automation.PSCredential' and try again.
At line:1 char:44
+ ii 'c:\Windows\System32\drivers\etc\hosts' -credential
+                                            ~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-Item], ParameterBindingException
    + FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.InvokeItemCommand

PS C:\Users\max_t>

Now, I've tried using this parameter to try open both an app ("notepad") and a file ("hosts") with user credentials (in this case as Admin).

So, I'm guessing (because there was no discussion), that this is a documentation bug and this parameter should be removed from this cmdlet. Is this the case?

Look, if I'm wrong in using this cmdlet, then fine! I just want to understand why not, as I think, I should be able to open a file using different credentials.

:)

@markekraus
Copy link
Contributor

@MaximoTrinidad I apologize if my response seems rushed or odd. However, this is the documented behavior of the -Credentials parameter on the Invoke-Item cmdlet, It is neither bug nor a documentation issue but by design. The parameter does not work with any of built-in PSProviders and is available on the cmdlet as a compatibility with 3rd-party and custom PSProviders that may require credential to invoke an item.

You may want to read up on PSProviders:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_providers?view=powershell-5.1

This includes a list of built in providers. One of which is the FileSystem provider which provide access to the files and folders on your system and remote systems through File Shares. Provider commands, such as Invoke-Item are generalized to work with whatever the PSProvider is abstracting, be it files, certificates, registry entries, etc.

The built-in providers are not the only providers available. In fact, SHiPS was recently announced which makes it even easier to create custom PSProvders. And example PSProvder that is not built-in and is widely used is the AD: PSDrive that is created when you import the Active Directory module.

There may be a need in a custom PSProvder for credentials to be supplied for various provider action concerning Items. In order to accommodate those PSProviders, the *-Item* cmdlets all expose a -Credential parameter, even though it is not used or supported in the built-in providers, such as FileSystem and Registry.

If your goal is to launch an application as another user you can use Start-Process -Credential See Start-Process.

If you think the documentation should be made more clear, you may open an issue on PowerShell/PowerShell-Docs.

While this Repository is open to general questions and support, its primary purpose is for reporting bugs, tracking work, and requesting features with PowerShell Core. When a documented behavior is presented as a problem the issue will be closed unless the suer is making a proposal to change the behavior. I don't believe changing the behavior in this instance is possible or desireable as there are other better means launch an application as another user.

If you would like general help with PowerShell you can use Gitter, Slack, Reddit, and StackOverflow where people like myself hang out and help with any questions you might have.

@MaximoTrinidad
Copy link
Author

@markekraus,

Awesome! Greatly Appreciate your response. Sorry for the rant!

Yes! Last night I went and looked at another route using the Start-Process, and for my surprise, the credential parameter didn't work neither.

I ended up using the "-Verb RunAs" parameter to accomplished what I needed. This time there were no notes like Invoke-Item. But, there's always a possibility that its a doc bug.

Well, I appreciate your comments.

Thank again,
Max

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-By Design The reported behavior is by design.
Projects
None yet
Development

No branches or pull requests

2 participants