-
Notifications
You must be signed in to change notification settings - Fork 1
/
Suspend-Computer.ps1
65 lines (60 loc) · 1.57 KB
/
Suspend-Computer.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
58
59
60
61
62
63
64
65
<#
.Synopsis
Send the suspend message to a computer
.DESCRIPTION
To accompany stop-computer, we need suspend-computer.
Great for knocking laptops off to be returned to users walking from the IT office.
See examples, Get-Help Suspend-Computer -examples
.EXAMPLE
Suspend-Computer -ComputerName "test","test2"
WARNING: Will send sleep command to: test test2
WARNING: Use "-Force" to execute this command
.EXAMPLE
Suspend-Computer -Verbose -force
VERBOSE: Suspend command sent to: localhost
.EXAMPLE
Suspend-Computer -Force -ComputerName user-laptop-346
#>
function Suspend-Computer
{
[CmdletBinding(
SupportsShouldProcess,
ConfirmImpact="High"
)]
Param
(
# Target Computer Name
[Parameter(
ValueFromPipelineByPropertyName=$true,
Position=0
)]
[string[]]
$ComputerName = "localhost"
,
[switch]
$Force
)
Begin
{
Write-Debug "Confirm Preference: $ConfirmPreference"
Write-Debug "Force Preference: $Force"
}
Process
{
if(-not $Force)
{
Write-Warning "Will send suspend command to: $ComputerName"
Write-Warning "Use `"-Force`" to execute this command"
}
if($Force)
{
Write-Verbose "Suspend command sent to: $ComputerName"
$ComputerName | Invoke-command -ScriptBlock {
#& "$env:SystemRoot\System32\rundll32.exe" powrprof.dll,SetSuspendState Standby
}
}
}
End
{
}
}