Advertisement
MuratYildirimoglu

Every computer a web server using Powershell

May 12th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. # Create the Web page, accumulate it with the relevant info
  2.  
  3. "<html>" > index.html
  4.  
  5. "<head>" >> index.html
  6.  
  7. "</head>" >> index.html
  8.  
  9. "<body>" >> index.html
  10.  
  11. "Computer Name: "+ [System.Net.Dns]::GetHostName() >> index.html
  12.  
  13. "<p>" >> index.html
  14.  
  15. "Operating System: "+(Get-CimInstance -ClassName Win32_OperatingSystem).caption >> index.html
  16.  
  17. "<p>" >> index.html
  18.  
  19. "User Name: "+(whoami)+" <p>" >> index.html
  20.  
  21. #IP address collection will be tricky
  22.  
  23. $VIPAddress=(Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter ("IPEnabled=TRUE") | Select-Object @{label="IPAddress";expression={$_.ipaddress[0]}},@{label="IPSubnet";expression={$_.IPSubnet[0]}},MACAddress,@{label="DefaultIPGateway";expression={$_.DefaultIPGateway[0]}},DHCPServer,DHCPEnabled,DNSDomain,DNSServerSearchOrder)
  24.  
  25. $length=$VIPAddress.length
  26.  
  27. #Now, display IP addresses for all enabled adapters
  28.  
  29. for($i=0;$i -lt $length;$i++){
  30.  
  31. "IP Address: "+$vipAddress[$i].ipaddress+" <p>" >> index.html
  32.  
  33. }
  34.  
  35. "</body>" >> index.html
  36.  
  37. "</html>" >> index.html
  38.  
  39. #Create “views” subfolder and copy index.html to it
  40.  
  41. md views
  42.  
  43. copy index.html views
  44.  
  45. #Install pode module for the current user. User may be a standard user.
  46.  
  47. Install-Module -Name ‘Pode’ -Scope ‘CurrentUser’ -force
  48.  
  49. #Start the Pode web server. IP address will be 127.0.0.1 because other ("real") addresses require the user to be an administrator
  50.  
  51. #Web site port should be between 1024-65535 so it will not meddle in other web sites on the computer, if any.
  52.  
  53. Start-PodeServer {
  54.  
  55. Add-PodeEndpoint -Address 127.0.0.1 -Port 6645 -Protocol Http
  56.  
  57. Add-PodeRoute -Method Get -Path ‘/’ -ScriptBlock {
  58.  
  59. Write-PodeViewResponse -Path ‘index.html’
  60.  
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement