squid808
squid808

Reputation: 1490

Invoking Read-Host cmdlet from within C# Custom Cmdlet

I'm writing a set of Powershell Cmdlets that require Oauth2 authentication. I currently am able to get to the point where a new browser window opens and the user copies out the Access Authentication Code to pass back to the cmdlets. However, this means I have to have a separate cmdlet that now accepts the Auth Code as input.

Is there any way to invoke the Read-Host? I've tried the instructions but despite being listed, ReadHostCommand isn't showing up under the Microsoft.PowerShell.Commands namespace, but something like WhereObjectCommand is.

I've tried Console.ReadLine() but it is just ignored when running the Cmdlet.

Upvotes: 3

Views: 1200

Answers (1)

Keith Hill
Keith Hill

Reputation: 201652

The ReadHostCommand is in the Microsoft.PowerShell.Commands namespace but you have to reference the Microsoft.PowerShell.Commands.Utility.dll assembly.

Upvotes: 4

Related Questions