- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2015 12:41 PM
We are working on Servicenow integration with Exchange server. When running a powershell script. we are getting below error
Has anyone faced this issue ?
*** Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.Stack Trace: at Microsoft.PowerShell.ConsoleHostUserInterface.HandleThrowOnReadAndPrompt()at Microsoft.PowerShell.ConsoleHostUserInterface.Prompt(String caption, String message, Collection`1 descriptions)at System.Management.Automation.Internal.Host.InternalHostUserInterface.Prompt(String caption, String message, Collection`1 descriptions)at Microsoft.PowerShell.Commands.ReadHostCommand.BeginProcessing()at System.Management.Automation.Cmdlet.DoBeginProcessing()at System.Management.Automation.CommandProcessorBase.DoBegin()
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2015 12:25 PM
You need to remove the Read-Host. To access your scratchpad variable, inside PowerShell, you identify it as:
$env:SNC_NetworkID
so your line above would be:
$sam = $env:SNC_NetworkID
Effectively, the scratchpad variable becomes an environment variable, hence the $env:
SNC_ identifies the scratchpad variable then you add the name of the variable you set in the PowerShell variables field on the Run PowerShell activity.
To make sure that your NetworkID variable has a value when it is passed, I would do something like this in your PowerShell script:
if(test-path env:\SNC_NetworkID){ #Notice this line does not have the "$" and includes a "\" - This is not a typo
$sam = $env:SNC_NetworkID #Notice this line includes the "$" and does NOT include the "\" - also not a typo
}
Then you could do an else{} if your NetworkID field was NULL.
Hope this helps,
Chad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2015 09:38 AM
Varsha,
Does your PowerShell script include any prompts for additional data? If so, it will fail because you are not able to interact with the PowerShell script while it is running. Say, for example, you run the following in a PowerShell console:
Read-Host -Prompt "What is your name?"
at the prompt you would see What is your name? and the console would wait for you to enter your name and press Enter. However, when running a Run PowerShell activity in a workflow, the PowerShell code is actually processed on your MID server in "NonInteractive mode" which means you cannot provide input to it.
If your PowerShell script requires input, you will have to pass that information as variables from the workflow, or gather it from other cmdlets in your code.
Hope this helps,
Chad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2015 11:12 AM
Thank you Chad for your input,
Script is reading only 1 input parameter
$sam = Read-Host "NetworkID?"
and I am passing variable in powershell activity
{"NetworkID": "${workflow.scratchpad.network_id}"}
Do you see anything missing ?
Regards
Varsha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2015 12:25 PM
You need to remove the Read-Host. To access your scratchpad variable, inside PowerShell, you identify it as:
$env:SNC_NetworkID
so your line above would be:
$sam = $env:SNC_NetworkID
Effectively, the scratchpad variable becomes an environment variable, hence the $env:
SNC_ identifies the scratchpad variable then you add the name of the variable you set in the PowerShell variables field on the Run PowerShell activity.
To make sure that your NetworkID variable has a value when it is passed, I would do something like this in your PowerShell script:
if(test-path env:\SNC_NetworkID){ #Notice this line does not have the "$" and includes a "\" - This is not a typo
$sam = $env:SNC_NetworkID #Notice this line includes the "$" and does NOT include the "\" - also not a typo
}
Then you could do an else{} if your NetworkID field was NULL.
Hope this helps,
Chad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2015 02:54 PM
Hello Chad,
This worked , Thanks a lot for your help
Regards
Varsha