-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-example.ps1
57 lines (49 loc) · 1.55 KB
/
app-example.ps1
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
ipmo pwsh
$app = Get-Pwsh
$app.get('/ping', { return "Connected" })
$app.get('/system-info', {
$data = @{
name = $env:COMPUTERNAME
domain = ($domain.joined())
has_admin = ($accounts.isAdminActivated())
installed_printers = ($printers.getInstalled())
available_printers = ($printers.getAvailable())
}
return $data
})
$app.get('/activate-admin', {
try {
if ($accounts.isAdminActivated() -eq $false) {
$accounts.activateAdmin()
$adm = $accounts.admin()
return "Administrator account was activated successfully with the following credentials:`nUsername: $($adm.Name)`nPassword: $($accounts.admin_password)`n"
}
return "Administrator account is already activated."
}
catch {
return "An error ocurred while trying to activate the administrator user:`n$_"
}
})
$app.post('/enter-domain', {
param(
[object] $data
)
return ($domain.enter($data.computer_name))
})
$app.post('/add-printers', {
param(
[object] $data
)
foreach ($p in $data.printers) {
try {
$printers.add($p)
$result += "`n'$p' added successfully."
}
catch { $result += "`nThere was an error trying to add '$p':`n$_" }
}
return $result
})
$app.listen(@{
port = 1100
expose = $true
})