Powershell Webserver

Powershell script that starts a webserver (without IIS). Powershell command execution, script execution, upload, download and other functions are implemented. Now here: https://github.com/MScholtes/TechNet-Gallery

 
 
 
 
 
4.5 Star
(2)
9,611 times
Add to favorites
Applications
6/8/2020
E-mail Twitter del.icio.us Digg Facebook
  • Disabling file upload/download
    2 Posts | Last post December 14, 2019
    • Hope this isn't too much of a newbie question but we have need to deploy some static pages without the file upload/download so it would be good to have a switch added to the script that turns this off. If I get time I will have a look at what this would entail but if this is something that could be added easily I am sure this would increase the usage.
    • Hello The Real Pobblebonk,
      
      the "PowerShell Webserver" was not intended to be a Ready-to-go solution, but a template for your own scripts. I use it as a construction kit of web server functions, most of the time I do not need all so I delete the unneeded. In your case please delete the lines from
      
      { $_ -like "* /download" } # GET or POST method are allowed for download page
      
      to the line before
      
      "GET /log"
      
      to eliminate the download and upload functions.
      
      Greetings
      
      Markus
      
      
  • Full download path
    2 Posts | Last post October 30, 2019
    • How can I get the full path to the file to be downloaded??
      
      I'd like to be able to use a link like: http://localhost:8080/folder/test.txt
      
      I need this to be able to feed a link into something to have it download certain files.
      
      It'd be nice to be able to have the option to show the directory listing of all the files and click on them.
      
      Thanks!!
      
    • Hello Elementix99,
      
      Microsoft has finally solved the problem of the missing questions so that I can answer now:
      
      I have included the functionality you request in the latest version 1.2 of the script. Please check if you're using the actual script.
      
      Greetings
      
      Markus
  • Jerry's test Question
    1 Posts | Last post October 14, 2019
  • How to get textarea value from header
    3 Posts | Last post January 27, 2018
    • Hi Markus,
      Thanks because you've create a wonderfull web .ps1. I'm trying to learn powershell and use your file to build a test intranet web. I have 1 question about textarea. I create a new hyperlink in web page (maybe call a new page). There is a textarea and a button. I need to get value of the textarea. So i see the code you wrote in /script page but i don't understand all. Plz explain this 2 problem:
      1. What does `r`n or `r`n$ or `r$ means? THat's new line character, right?
      $_.Substring(0, $_.IndexOf("`r`n`r`n"))
      $PASSWORDLIST = $_.Substring($_.IndexOf("`r`n`r`n") + 4) -replace "`r`n$" -replace "`r$"
      2. What's the different between getting value of textbox and textarea?
      When i copied the same code for textbox to get value of textare, i got error "Received corrupt or incomplete form data". I think variable is null. ie:
      if ($_.Substring(0, $_.IndexOf("`r`n`r`n")) -match "Content-Disposition: form-data; name=(.*)")
      {												
      $HEADERNAME = $MATCHES[1] -replace '\"'																								if ($HEADERNAME -eq "TextArea1")												{ 													$TEMP= $_.Substring($_.IndexOf("`r`n`r`n") + 4) -replace "`r`n$" -replace "`r$"
      }
    • Hello Khoa_PD,
      
      here are the answers to your first question.
      
      `r`n is the new line sequence on Windows Systems, `r is the new line sequence on Unix systems. I replace both sequences because I do not know on which OS the client browser runs on.
      The $ in regular expressions (which -replace uses) mean "at the end of the string". So the expression -replace "`r`n$" -replace "`r$" mean: replace a new line sequence at the end of the string with nothing.
      
      $_.Substring(0, $_.IndexOf("`r`n`r`n")) means the part of the string from position 0 (the first character) to the first occurence of "`r`n`r`n" - two new line sequences - in the string. This divides the header meta data (this includes the html field name) from the data (this includes the field value).
      
      $_.Substring($_.IndexOf("`r`n`r`n") + 4) -replace "`r`n$" -replace "`r$" replaces the closing new line sequence in the header data.
      
      For the answer to your second question I need some time to investigate.
      
      Greetings
      
      Markus
      
      
      
    • Hello Khoa_PD,
      
      here is the answer to your second question.
      
      I added the following line to the existing form html code for 'GET /upload':
      
      <textarea name="TextArea1" rows=8 cols=80></textarea>
      
      With your code sample I was able to receive the textarea field data. So I cannot reproduce your error.
      
      Can you give me more information or code so I might help to solve your problem?
      
      Greetings
      
      Markus
      
  • Wie Bild einfügen ?
    3 Posts | Last post March 05, 2017
    • Ist es möglich ein Bild <img src=???> einzufügen? Wie muss die Refernz-url aussehen?
      
      Vielen Dank
      
      Matthias Hahn 
    • Hallo Mattias,
      
      Bitte entschuldige die späte Antwort, ich war unterwegs.
      Über die Download-Funktion ist es möglich, Bilder einzubetten. 
      Z.B. wird ein Bild "NicePicture.jpg" im Verzeichnis des Skriptes über <img src="/download?filepath=NicePicture.jpg" alt="Nice Picture"> eingebunden.
      
      Grüße
      
      Markus
      
      
      Hello Matthias,
      
      please excuse the late reply, I was on the road.
      Using the download function it is possible to embed images.
      E.g. a picture "NicePicture.jpg" located in the directory of the script is integrated via <img src = "/download?filepath=NicePicture.jpg" alt="NicePicture">.
      
      Greetings
      
      Markus
      
    • Hallo Matthias,
      
      eine kleine Korrektur: das Bild wird im aktuellen Powershell-Verzeichnis gesucht und nicht im Verzeichnis des Skripts.
      Eine Pfadangabe zum Bild kann aber wie folgt angegen werden:
      <img src="/download?filepath=/img/test.jpg" alt="Test">
      
      Grüße
      
      Markus
      
      
      Hello Matthias,
      
      a small correction: the image is searched in the current Powershell directory and not in the directory of the script.
      However, a path to the image can be specified as follows:
      <img src="/download?filepath=/img/test.jpg" alt="Test">
      
      Greetings
      
      Markus