| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Adds PowerShell runtime support to the Kestrun server. |
| | 4 | | .DESCRIPTION |
| | 5 | | This cmdlet allows you to register a PowerShell runtime with the Kestrun server. |
| | 6 | | It can be used to execute PowerShell scripts and commands in the context of the Kestrun server. |
| | 7 | | .PARAMETER Server |
| | 8 | | The Kestrun server instance to which the PowerShell runtime will be added. |
| | 9 | | .PARAMETER PassThru |
| | 10 | | If specified, the cmdlet will return the modified server instance. |
| | 11 | | .EXAMPLE |
| | 12 | | $server | Add-KrPowerShellRuntime -PathPrefix '/ps' |
| | 13 | | This example adds PowerShell runtime support to the server, with a path prefix of '/ps'. |
| | 14 | | .EXAMPLE |
| | 15 | | $server | Add-KrPowerShellRuntime |
| | 16 | | This example adds PowerShell runtime support to the server without a path prefix. |
| | 17 | | .NOTES |
| | 18 | | This cmdlet is used to register a PowerShell runtime with the Kestrun server, allowing you to execute PowerShell |
| | 19 | | #> |
| | 20 | | function Add-KrPowerShellRuntime { |
| | 21 | | [KestrunRuntimeApi('Definition')] |
| | 22 | | [CmdletBinding()] |
| | 23 | | [OutputType([Kestrun.Hosting.KestrunHost])] |
| | 24 | | param( |
| | 25 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | 26 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | 27 | |
|
| | 28 | | [Parameter()] |
| | 29 | | [switch]$PassThru |
| | 30 | | ) |
| | 31 | | begin { |
| | 32 | | # Ensure the server instance is resolved |
| 1 | 33 | | $Server = Resolve-KestrunServer -Server $Server |
| 1 | 34 | | if ($null -eq $Server) { |
| 0 | 35 | | throw 'Server is not initialized. Please ensure the server is configured before setting options.' |
| | 36 | | } |
| | 37 | | } |
| | 38 | | process { |
| | 39 | |
|
| 2 | 40 | | $Server.AddPowerShellRuntime() | Out-Null |
| | 41 | |
|
| 1 | 42 | | if ($PassThru.IsPresent) { |
| | 43 | | # if the PassThru switch is specified, return the server instance |
| | 44 | | # Return the modified server instance |
| 0 | 45 | | return $Server |
| | 46 | | } |
| | 47 | | } |
| | 48 | | } |
| | 49 | |
|