Hi,
Of late i have been experiencing a strange behavior in powershell. I have written a script that will execute commands in powershell for every 5 minutes. First time, it will try to connect to my exchange server using New-pssession and saves the session if it is successful. After executing few commands, the execution fails with below errors :
Error 1 :
Exception calling “GetSteppablePipeline” with “1” argument(s): “Exception calling
“PromptForCredential” with “4” argument(s): “A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: Enter your credentials for http://serverName/powershell?serializationLevel=Full.””|
StackTrace : at System.Management.Automation.Runspaces.AsyncResult.EndInvoke()
at System.Management.Automation.PowerShell.EndInvoke(IAsyncResult asyncResult)
Error 2
The term ‘Test-ImapConnectivity’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again
Is there any setting related to powershell that is causing this ? I have checked user permissions, tried to connect manually and executed commands.Everything looks fine
Where are you running this? Remote run spaces don’t support prompting; you’d need to provide all the parameters - in this case I’m guessing a credential - with the command so it doesn’t need to prompt.
The script is run in a client machine.Credential is provided with New-Pssession command.The erorrs are occuring during invoking command (BeginInvoke) and ending the invoke operation(EndInvoke).
Roughly the script to connect to remote exchange server is :
Ah. Things do work a bit differently in C# than in PowerShell per se; there’s a lot of state maintenance and such that the console provides which a base run space does not. In particular, when a prompt is required, your app is the one required to deal with it, and it isn’t - hence, the error. Passing a credential to a runspace is only useful when that runspace is operating against its local resources - if it needs to connect to something, the credential can’t be delegated further without an environmental configuration change. That appears, from the error, to be what’s happening. But I’m going to be of minimal help, because I take for granted all the magic built into the console, which you don’t have available.