-
Notifications
You must be signed in to change notification settings - Fork 1
/
opschallengeclass12.ps1
129 lines (68 loc) · 2.3 KB
/
opschallengeclass12.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Script Name opschallengeclass12.ps1
# Author Bill Kachersky
# Date of last revision 08/10/2021
# Description of purpose Ops Challenge Class 12
# OPS CHALLENGE TASKS BEGIN
# VARIABLES
$NetRepFull=ipconfig /all
$DesktopPath=[Environment]::GetFolderPath("Desktop")
# FUNCTIONS
# Task 1, 2 & 3
function NetworkReportandDestroy {
echo "Outputting Network Report to Desktop..."
sleep 5
$NetRepFull | Out-File -FilePath $DesktopPath\network_report.txt
echo "Report Generated.. Grabbing IPv4 data!"
sleep 3
Select-String -Path "$DesktopPath\network_report.txt" -Pattern 'IPv4'
sleep 2
echo "IPv4 Data captured, deleting source file now."
sleep 3
rm $DesktopPath\network_report.txt
sleep 3
echo "Deleted!"
}
# Stretch 1
function NetRep2Clip {
Set-Clipboard -Value $NetRep2Mem | Get-Clipboard | Select-String -Pattern "IPv4"
}
# Stretch 2
function pingpong {
ping 192.168.0.1
}
# Stretch 3
function interweb {
If (Test-Connection google.com -count 4 -quiet) {
Write 'The host responded'
}
}
# MAIN
<#
Task 1, 2, and 3
1 - Create a local file called network_report.txt that holds the contents of an ipconfig /all command.
2 - Use Select-String to search network_report.txt and return only the IP version 4 address.
3 - Remove the network_report.txt when you are finished searching it.
#>
NetworkReportandDestroy
sleep 5
# Stretch Goal 1 - Instead of creating network_report.txt, use piping to store the output in memory and search it there.
echo "Now let's try that again, but commit it to memory this time!"
sleep 3
echo "Working, stand by!"
sleep 2
NetRep2Clip
sleep 5
echo "Looks like that should do it.. Check your clipboard, hit your Windows key + V to see if it took!"
sleep 5
# Stretch Goal 2 - Have your script test whether the network adapter is sending and receiving packets correctly.
echo "Now let's see if we can ping the Network adapter.."
sleep 3
pingpong
sleep 5
# Stretch Goal 3 - Have your script test connectivity to the internet
echo "Now let's see if we're able to access the interwebs"
sleep 2
interweb
sleep 2
echo "Complete!"
# END