Executing GUI Form on a remote Computer

Welcome Forums General PowerShell Q&A Executing GUI Form on a remote Computer

Viewing 3 reply threads
  • Author
    Posts
    • #252194
      Participant
      Topics: 2
      Replies: 5
      Points: 62
      Rank: Member

      Greetings.

      Please, I tried executing a custom GUI Form script on a remote desktop. But when ever I tried doing that i got the error message below. What could be best way to approach this.

      <#—————————————————- code line Below ———————————————————————#>

      • This topic was modified 1 month ago by grokkit.
    • #252203
      Senior Moderator
      Topics: 10
      Replies: 168
      Points: 899
      Helping Hand
      Rank: Major Contributor

      Instead of trying to send your script in the -ScriptBlock {} parameter, what you want to do is send it with -FilePath, like this:

      Replace “path_to_your_script” with whatever the correct path to the script is on your local machine, and Invoke-Command will send it to the specified computer and execute it. Here is some further reading: Use PowerShell Invoke-Command to run scripts on remote computers.

    • #252221
      Participant
      Topics: 2
      Replies: 5
      Points: 62
      Rank: Member

      While trying the suggestion above, i got the below error message.

       

      C:\Powershell\scripts> Invoke-Command -ComputerName MX623693LFM -FilePath .\Get-UCForm.ps1

      Exception calling “ShowDialog” with “0” argument(s): “Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the
      ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.”
      + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : InvalidOperationException

      • This reply was modified 1 month ago by Albert1230.
    • #252233
      Participant
      Topics: 8
      Replies: 568
      Points: 2,171
      Helping Hand
      Rank: Community Hero

      If you’re trying to open a GUI on a remote session, there are certain security settings that restrict or prevent that. You for sure need to execute it as the user that has the active session. An alternate approach to just using Invoke-Command is to use the task scheduler to run as the user. I’ve personally just targeted a group like “Users” to target without knowing which user.

      The other part of what you’re trying you need to consider is the remote system has to know/have access to the script or function. You specify just a filename to the remote computer. Depending on where that profile loads by default, there would need to exist this file. In your C:\Powershell\Scripts folder this file works fine. If this file exists on the remote PC, then simply change to the full path

      If it doesn’t exist and you don’t intend to put a copy there, then you need to provide that definition to the remote runspace in some form or fashion. One way is to dot source the script but if you’re already invoking a remote command, then reaching out to a third host is subject to the double hop issue. You could simply provide the definition in the scriptblock

Viewing 3 reply threads
  • You must be logged in to reply to this topic.