1+ <#
2+
3+ . NOTES
4+ v1.6 silversword411 Making into a function
5+ v1.7 silversword411 Adding Custom Field AuditSCOtherDisable Disables check
6+
7+ TODO: Add detection of other remote access systems
8+ -AuditSCOtherDisable {{agent.AuditSCOtherDisable}}
9+ #>
10+ param (
11+ [string ] $SCURLtocheck , # The URL to check against the service path
12+ [Int ] $AuditSCOtherDisable , # Disable
13+ [switch ] $debug
14+ )
15+
16+ # check for Win7 and exit if true
17+ $OSVersion = (Get-WmiObject Win32_OperatingSystem).Version
18+ if ($OSVersion.StartsWith (" 6.1" )) {
19+ Write-Output " Running on Windows 7. Exiting..."
20+ Exit
21+ }
22+
23+ # See if Custom Field has disabled AuditSCOtherDisable
24+ Write-Debug " AuditSCOtherDisable: $AuditSCOtherDisable "
25+ if ($AuditSCOtherDisable ) {
26+ Write-Output " Other SC check disabled."
27+ Exit 0
28+ }
29+
30+ function Check-SCServicePath {
31+
32+ Write-Output " ################# Check ScreenConnect Service Path #################"
33+
34+ # For setting debug output level. -debug switch will set $debug to true
35+ if ($debug ) {
36+ $DebugPreference = " Continue"
37+ $ErrorActionPreference = ' Continue'
38+ Write-Debug " Debug mode enabled"
39+ }
40+ else {
41+ $DebugPreference = " SilentlyContinue"
42+ $ErrorActionPreference = ' SilentlyContinue'
43+ }
44+
45+ # Get all ScreenConnect services
46+ $SCServices = Get-Service | Where-Object { $_.Name -match " ScreenConnect Client*" }
47+
48+ $servicesNotContainingUrl = @ ()
49+
50+ foreach ($service in $SCServices ) {
51+ $serviceDetail = Get-CimInstance - ClassName Win32_Service - Filter " Name = '$ ( $service.Name ) '"
52+ if ($serviceDetail.PathName -notlike " *$SCURLtocheck *" ) {
53+ $servicesNotContainingUrl += $service
54+ }
55+ }
56+
57+ if ($servicesNotContainingUrl.Count -gt 0 ) {
58+ Write-Output " WARNING: ScreenConnect services do not contain '$SCURLtocheck ' in their path."
59+
60+ foreach ($service in $servicesNotContainingUrl ) {
61+ $serviceDetail = Get-CimInstance - ClassName Win32_Service - Filter " Name = '$ ( $service.Name ) '"
62+ Write-Debug " serviceDetail: $serviceDetail "
63+ $path = $serviceDetail.PathName
64+ Write-Debug " Path: $path "
65+ # Extract the text between "&h=" and "&p"
66+ $startIndex = $path.IndexOf (" &h=" ) + 3
67+ if ($startIndex -gt 2 ) {
68+ # Check if "&h=" exists
69+ $endIndex = $path.IndexOf (" &p" , $startIndex )
70+ if ($endIndex -gt $startIndex ) {
71+ # Check if "&p" exists after "&h="
72+ $extractedText = $path.Substring ($startIndex , $endIndex - $startIndex )
73+ Write-Output " Other SC server URLs: $ ( $extractedText ) "
74+ }
75+ }
76+ }
77+ Exit 1
78+ }
79+ else {
80+ Write-Output " AllGood: All ScreenConnect services contain '$SCURLtocheck ' in their path."
81+ }
82+ }
83+
84+ Check- SCServicePath
0 commit comments