en-US/about_PSApi.help.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
TOPIC
    about_PSApi
 
SHORT DESCRIPTION
    Provides an overall description of the PSApi module and how to use it. The
    information below is an abbreviated version of the information found at
    https://github.com/NotNotWrongUsually/PSApi
 
LONG DESCRIPTION
    The PSApi module takes a function from your current session and publishes it
    as a webservice. Using defaults your command will be exposed at:
 
    http://localhost/PSApi/<your-command>
 
    Using the parameters for the command you can modify the path, port, logging
    location etc. Refer to the help on Publish-Command for more information
    about the options.
 
    Any parameters for a published command can be supplied in the url query
    string.
 
RETURN TYPES
     
    [XML]
    is turned into a string by using the OuterXml property of the object.
 
    [System.Drawing.Image]
    will be converted to png format and presented in the browser.
 
    [Microsoft.Powershell.Commands.HtmlWebResponseObject]
    will be turned into a string by using the content property, so only the
    actual html is passed on.
 
    [String]
    will be sent with a content type of text/html. For an exception refer to the
    note on JSON below.
 
    JSON: There is no specific JSON type. Even content created with
    ConvertTo-Json is just listed as [String]. To present the correct
    content-type for JSON a test is performed on [String] objects. If an object
    can be be piped to ConvertFrom-Json without raising an exception the
    content-type will be set to application/json. The Test-Json cmdlet is not
    used for this as it appears utterly broken from testing.
 
    [Everything else]
    Anything that is not one of the above types will be stringified with the
    Out-String cmdlet and set to a content-type of text/plain. Notably this
    means that most things will look exactly like they do in the Powershell
    console.
 
EXAMPLES
 
    EXAMPLE 1:
 
    Creating a simple monitoring API showing the processes using most CPU time
  
    PS > function Get-HighCpuConsumers ($Top=5) {
    >> Get-Process | Sort-Object CPU -Descending |
    >> Select-Object Name, CPU, StartTime -First $Top |
    >> ConvertTo-Json
    >> }
 
    PS > Publish-Command Get-HighCpuConsumers
 
    Going to
     
    http://myhostname/PSApi/Get-HighCpuConsumers
     
    or alternatively
 
    http://myhostname/PSApi/Get-HighCpuConsumers?number=<x>
     
    Will display JSON with the relevant information for the machine.
 
    EXAMPLE 2:
 
    Serving an image
 
    PS > function Get-Image {
    >> New-Object System.Drawing.Bitmap -ArgumentList "C:\some_picture.jpg"
    >> }
 
    Going to http://myhostname/PSApi/Get-Image will display the picture.
 
SEE ALSO
    Help Publish-Command for more examples