Skip to content

Commit ebb4eae

Browse files
feat: Stop-OpenXML ( Fixes #29 )
1 parent d5a7f0f commit ebb4eae

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Commands/Stop-OpenXML.ps1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function Stop-OpenXML {
2+
<#
3+
.SYNOPSIS
4+
Stops an OpenXML Server
5+
.DESCRIPTION
6+
Stops a server running from an OpenXML.
7+
.NOTES
8+
This will stop any jobs with HTTP listeners and OpenXML
9+
#>
10+
param(
11+
# The input object.
12+
# Any input without an HttpListener and OpenXML property will be ignored.
13+
[Parameter(ValueFromPipeline)]
14+
[PSObject]
15+
$InputObject,
16+
17+
# If set, will pass thru the input.
18+
[switch]
19+
$PassThru
20+
)
21+
22+
process {
23+
# If the input is lacking a listener or OpenXML, return
24+
if (-not $InputObject.HttpListener -or -not $InputObject.OpenXML) {
25+
# (pass thru the input if we asked)
26+
if ($PassThru) {
27+
return $InputObject
28+
}
29+
return
30+
}
31+
32+
# Stop the listener
33+
$InputObject.HttpListener.Stop()
34+
# and attempt to stop the job (ideally so that it reports as stopped, not completed)
35+
if ($InputObject.StopJob -is [Management.Automation.PSMethod]) {
36+
$InputObject.StopJob()
37+
}
38+
if ($PassThru) {
39+
return $InputObject
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)