locked
Interactive sessions on remote powershell? RRS feed

  • Question

  • Hi guys,

    I have a powershell scripts that uses an interactive InputBox() method to collect the user's input. I'm trying to run it on a remote server, but get an error that the method can't run since the Posh session is not interactive.

    How do I open an interactive session?

    I've tried with "new-pssession" cmdlet but I read here that this is not supported:
    "Interactive native windows console commands are not supported in a remote powershell session. I know this sounds dumb, but currently this is the case (as of PowerShell v4.0)."

    https://stackoverflow.com/questions/21466372/execution-of-interactive-command-in-remote-powershell-session-not-working

    Pretty new to Powershell, appreciate any help I can get. Thanks! 

    My code looks like this:

    #prompting for GUI boxes
    Add-Type -AssemblyName Microsoft.VisualBasic
    $EventNo = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the event ID you want to create","Event ID Input","1")
    if($EventNo.Length -eq 0){
        exit
    }
    $EventSource = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the event source","Event Source","My Task Source")
    
    if($EventSource.Length -eq 0){
        exit
    }
    #Create a custom event source
    New-EventLog -Source $EventSource -LogName 'Operations Manager'
    #Write the event
    Write-EventLog -LogName 'Operations Manager' -Source $EventSource -EntryType Warning -EventId $EventID -Message "This is a test event created by task"
    #Show result to user
    [Microsoft.VisualBasic.Interaction]::MsgBox("The event with event ID '$EventNo' and Source '$EventSource' has been created in the Application log")
    exit
    

    Works like a charm on the local machine.


    Sam (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" wherever applicable. Thanks!)

    Sunday, March 18, 2018 1:52 PM

Answers

  • Can't be done remotely.  You must use PowerShell methods that do not produce GUI bits.

    You can use "Read-Host"


    \_(ツ)_/


    Sunday, March 18, 2018 7:38 PM

All replies

  • Can't be done remotely.  You must use PowerShell methods that do not produce GUI bits.

    You can use "Read-Host"


    \_(ツ)_/


    Sunday, March 18, 2018 7:38 PM
  • Well, that's a bummer. Was looking forward to not expose the user to Powershell window.

    Anyways, thanks for your help.

    Cheers


    Sam (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" wherever applicable. Thanks!)

    Monday, March 19, 2018 7:15 AM
  • Why do you have to do this that way.  All commands have remoting capability start by reading all of the help for you commands.


    \_(ツ)_/

    Monday, March 19, 2018 7:35 AM
  • I'll be wrapping these scripts up in SCOM MP (xml) and thought of a better presentation for input and output to the admin to make them more 'user-friendly".

    Anyways, I'll try using read-host to see if I can do anything with it.

    Cheers


    Sam (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" wherever applicable. Thanks!)


    Monday, March 19, 2018 8:07 AM