PowerShell Server 2016
PowerShell Server 2016
Questions / Feedback?

ASP.NET Intrinsic Objects

Besides running standard PowerShell scripts, you can interact with the HTTP runtime through the use of the ASP.NET intrinsic objects like HttpRequest and HttpResponse. Because of the threading model used by PowerShell, those objects are not directly accessible through HttpContext.Runtime.

  • $Request: Contains the HttpRequest object.
  • $Server: Contains the HttpServerUtility object.
  • $Session: Contains the HttpSessionState object.
  • $Application: Contains the HttpApplicationState object.
  • $Response: Contains the HttpResponse object. You can write directly to the response stream from code if you want, or you can use write-host and friends as well.
  • $Cache: Contains the HttpCache object.
  • $Context: The HttpContext object associated with the current request.

These objects are used in exactly the same way as in regular ASP.NET applications.

Here is an example script that will dump all the values in the HttpRequest object to a simple HTML page:


  <% $request.params | %{
      write-output "$_ = $($request[$_])<br/>"
  } %>

You can see this sample uses the PowerShell Write-Output cmdlet to generate the output

 
 
Copyright (c) 2017 /n software inc. - All rights reserved.
PowerShell Server 2016 - Version 16.0 [Build 6335]