ever-works-node 0.0.0-stage → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,67 @@
1
+ <#
2
+ .SYNOPSIS
3
+ Remove the Ever Works node service / scheduled task from this machine.
4
+
5
+ .DESCRIPTION
6
+ Stops and removes whichever registration `install-service.ps1`
7
+ created. It does NOT unenroll the node - the credential and the
8
+ platform-side registration are separate concerns, and deleting a
9
+ service should never silently revoke a machine's identity.
10
+
11
+ To retire the machine completely:
12
+
13
+ ever-works-node unenroll
14
+
15
+ .PARAMETER Name
16
+ Service / task name. Default: EverWorksNode
17
+ #>
18
+ [CmdletBinding()]
19
+ param(
20
+ [string] $Name = 'EverWorksNode'
21
+ )
22
+
23
+ $ErrorActionPreference = 'Stop'
24
+
25
+ function Test-Administrator {
26
+ $identity = [Security.Principal.WindowsIdentity]::GetCurrent()
27
+ $principal = New-Object Security.Principal.WindowsPrincipal($identity)
28
+ return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
29
+ }
30
+
31
+ if (-not (Test-Administrator)) {
32
+ throw 'This script must run from an elevated PowerShell session.'
33
+ }
34
+
35
+ $removed = $false
36
+
37
+ $service = Get-Service -Name $Name -ErrorAction SilentlyContinue
38
+ if ($null -ne $service) {
39
+ $nssm = Get-Command 'nssm' -ErrorAction SilentlyContinue
40
+ if ($null -ne $nssm) {
41
+ # `nssm stop` waits for the node's own drain before killing it.
42
+ & $nssm.Source stop $Name | Out-Null
43
+ & $nssm.Source remove $Name confirm | Out-Null
44
+ }
45
+ else {
46
+ Stop-Service -Name $Name -Force
47
+ & sc.exe delete $Name | Out-Null
48
+ }
49
+ Write-Host "Removed Windows service '$Name'."
50
+ $removed = $true
51
+ }
52
+
53
+ $task = Get-ScheduledTask -TaskName $Name -ErrorAction SilentlyContinue
54
+ if ($null -ne $task) {
55
+ try { Stop-ScheduledTask -TaskName $Name } catch {}
56
+ Unregister-ScheduledTask -TaskName $Name -Confirm:$false
57
+ Write-Host "Removed scheduled task '$Name'."
58
+ $removed = $true
59
+ }
60
+
61
+ if (-not $removed) {
62
+ Write-Host "Nothing named '$Name' is registered on this machine."
63
+ }
64
+
65
+ Write-Host ''
66
+ Write-Host 'The node is still enrolled. To retire it on the platform too:'
67
+ Write-Host ' ever-works-node unenroll'