-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy path20_1.ps1
More file actions
32 lines (32 loc) · 940 Bytes
/
Copy path20_1.ps1
File metadata and controls
32 lines (32 loc) · 940 Bytes
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
function Set-ComputerState {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[string[]]$ComputerName,
[Parameter(Mandatory=$True)]
[ValidateSet('Restart','Shutdown')]
[string]$Action,
[switch]$Force
)
BEGIN {}
PROCESS {
ForEach ($comp in $ComputerName) {
$params = @{'Computername' = $comp}
# force?
if ($force) {
$params.Add('Force',$true)
}
# which action?
If ($Action -eq 'Restart') {
Write-Verbose "Restarting $comp (Force: $force)"
Restart-Computer @params
} else {
Write-Verbose "Stopping $comp (Force: $force)"
Stop-Computer @params
}
}
} #PROCESS
END {}
}