-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwakeonlan.psm1
73 lines (61 loc) · 1.78 KB
/
wakeonlan.psm1
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
function Get-AccessToken
(
[Parameter(Mandatory=$true)]
[string] $TenantID,
[Parameter(Mandatory=$true)]
[string] $ClientID,
[Parameter(Mandatory=$true)]
[securestring] $ClientSecret,
[Parameter(Mandatory=$true)]
[string] $ServerApplicationID
)
{
$uri = "https://login.microsoftonline.com/$TenantID/oauth2/v2.0/token"
$form = @{
client_id = $ClientID
scope = "api://$ServerApplicationID/.default"
client_secret = ConvertFrom-SecureString $ClientSecret -AsPlainText
grant_type = "client_credentials"
}
$result = Invoke-RestMethod -Uri $uri -Method Post -Form $form
return ConvertTo-SecureString $result.access_token -AsPlainText
}
function Get-Computer
(
[Parameter(Mandatory=$true)]
[string] $Url,
[Parameter(Mandatory=$true)]
[securestring] $AccessToken,
[string] $Name,
[switch] $SkipCertificateCheck
)
{
$uri = "$Url/api/wakeonlan/$Name";
return Invoke-RestMethod `
-Uri $uri `
-SkipCertificateCheck:$SkipCertificateCheck `
-Token $AccessToken `
-Authentication Bearer
}
function Set-Computer
(
[Parameter(Mandatory=$true)]
[string] $Url,
[Parameter(Mandatory=$true)]
[securestring] $AccessToken,
[Parameter(Mandatory=$true)]
[string] $Name,
[Parameter (Mandatory=$true, ValueFromPipeline)]
[pscustomobject] $Computer,
[switch] $SkipCertificateCheck
)
{
$uri = "$Url/api/wakeonlan/$Name";
return $Computer | ConvertTo-Json | Invoke-RestMethod `
-Method PUT `
-Uri $uri `
-ContentType "application/json" `
-SkipCertificateCheck:$SkipCertificateCheck `
-Token $AccessToken `
-Authentication Bearer
}