-
Notifications
You must be signed in to change notification settings - Fork 17
/
Lab5.ps1
55 lines (49 loc) · 1.54 KB
/
Lab5.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
function Get-L4ComputerName {
Get-CimInstance -Classname Win32_ComputerSystem | Select-Object Name
}
function Get-L4Processes {
Get-Process | Sort-Object -Descending -Property CPU | Select-Object -First 5
}
function Get-bitsService {
$bitsService = "bits"
$bitsrunning = Get-Service bits
if ($bitsrunning.Status -eq "Running") {
Stop-Service bits -Force -NoWait
}
if ($bitsService.Status -eq "Stopped") {
Start-Service -Name bits -Force -NoWait
}
}
function Get-ServicesStartingWithS
{
Get-Service | Where-Object {$_.Name -like "s*"}
}
function Get-Lab5Info {
[CmdletBinding()]
param (
[Parameter()]
[string[]]
$ComputerName)
Invoke-Command -ComputerName $ComputerName -ScriptBlock {
Get-Service | Where-Object {$_.Name -like "s*"}
Get-Process | Sort-Object -Descending -Property CPU | Select-Object -First 5
}
$cred = Get-Credential
$session1 = New-PSSession -ComputerName $ComputerName -Credential $cred
Invoke-Command -Session $session1 -ScriptBlock {
$bitsService = "bits"
$bitsrunning = Get-Service $bitsService
if ($bitsrunning.Status -eq "Running") {
Stop-Service -Name bits -Force -NoWait
Start-Sleep -Seconds 20
}
Get-Service bits
$bitsrunning = Get-Service $bitsService
if ($bitsrunning.Status -eq "Stopped") {
Start-Service -Name bits
Start-Sleep -Seconds 20
}
Get-Service bits
}
Get-PSSession | Remove-PSSession
}