none
PowerShell Remoting Launching Web Browser RRS feed

  • Question

  • I am attempting to generate webpages using the Razor Engine. I want to allow the user to be able to launch that webpage on their local device browser while in the session. I am having a very hard time finding a logical way to get this task completed. It seems that the Invoke-Item when placed into the ps1 script is running on the server, but not returning the browser to the client-side device.

    function Get-File{
       param(
        [Parameter(Mandatory=$true,HelpMessage='Please enter a valid Detonation ID')][string]$p
       )  
      If($p -match '[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}')
            {
                $fileResult= Invoke-WebRequest -Uri https://url.com/rapi/file/$p/file-WebSession $currentsession
                # End API Call
                Write-Verbose -Message 'Displaying File in web page....'
                # Create Web Page      
                $fileString= $fileResult.RawContent
                $template = Get-Content -Path '\\p-servera\D$\Web Templates\filetemplate.htm'
                $model = New-Object -TypeName RazorEngine.Templating.DynamicViewBag
                $model.AddDictionaryValues(@{File= $fileString})
                [RazorEngine.Razor]::Parse($template, $model) |
                Out-File -FilePath $env:TEMP\file.htm
                }
                else
                {
                  Write-Warning -Message 'Please enter a valid Detonation UUID'
                }
              }
            }
    The razor engine takes care of all of the templating my issue is getting the template to launch in a client-side browser while in a remote PS Session. 



    Tuesday, January 24, 2017 4:08 PM

Answers

  • You are extracting one value from the page.  Just use the parsed HTML to find the object and get its value.


    \_(ツ)_/

    Tuesday, January 24, 2017 4:49 PM

All replies

  • You cannot remotely launch a local application.  Remoting does not work that way.  The remote script only affects the remote system.


    \_(ツ)_/

    Tuesday, January 24, 2017 4:20 PM
  • Are there any work arounds to pull that data into the client-side device? Like distributing a script?
    Tuesday, January 24, 2017 4:22 PM
  • You cannot run a browser remotely.  It will fail to return anything and may crash teh device.

    Post your issue to Razor as you are using their software which is not supported in this forum.


    \_(ツ)_/

    Tuesday, January 24, 2017 4:28 PM
  • Why does this have to be done remotely?  The code will run on any Windows system.


    \_(ツ)_/

    Tuesday, January 24, 2017 4:31 PM
  • Well, I wanted to keep the scripts centralized because I have 200 users who access them. I suppose I could keep this one script to be run locally which would remedy all of the issues that I am having. But if I want to update/modify the script. It's going to be a mission to get everyone else to get the new script.
    Tuesday, January 24, 2017 4:37 PM
  • Also, it would require the installation of the Razor libraries into everyone's GAC across the network. So if there is a way to take part of the script and localize it I would do it.
    Tuesday, January 24, 2017 4:41 PM
  • Well, I wanted to keep the scripts centralized because I have 200 users who access them. I suppose I could keep this one script to be run locally which would remedy all of the issues that I am having. But if I want to update/modify the script. It's going to be a mission to get everyone else to get the new script.

    Sign the script and place it on a the network and let users run it from the network.


    \_(ツ)_/

    Tuesday, January 24, 2017 4:44 PM
  • Also, it would require the installation of the Razor libraries into everyone's GAC across the network. So if there is a way to take part of the script and localize it I would do it.

    Why do you need Razor.  Just build the template i PowerShell using PowerShell syntax.  Razor is overkill for most things in PowerShell.  

    You also have the option of not installing Razor in the GAC and just importing it from a share in the script.


    \_(ツ)_/


    • Edited by jrv Tuesday, January 24, 2017 4:47 PM
    Tuesday, January 24, 2017 4:45 PM
  • I think you're right in this case, I've been thinking the same.... But, how would I take the data and place it into an HTML template? Is that possible?
    Tuesday, January 24, 2017 4:47 PM
  • You are extracting one value from the page.  Just use the parsed HTML to find the object and get its value.


    \_(ツ)_/

    Tuesday, January 24, 2017 4:49 PM