Skip to content

Commit a070d6c

Browse files
Merge pull request #145 from huntresslabs/Alan-Huntress-patch-33
Improved post-uninstall service removal
2 parents 36e779d + f9f2fa0 commit a070d6c

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

Datto-RMM/scripts/InstallHuntress.dattormm.comstore.ps1

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1515
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1616
#
17-
# Authors: Alan Bishop, Sharon Martin, John Ferrell, Dave Kleinatland, Cameron Granger
17+
# Authors: Alan Bishop, Sharon Martin, John Ferrell, Dave Kleinatland, Evan Shewchuk
1818

1919

2020
# The Huntress installer needs an Account Key and an Organization Key (a user specified name or description) which is used to affiliate an Agent with a
@@ -104,7 +104,7 @@ $estimatedSpaceNeeded = 200111222
104104
##############################################################################
105105

106106
# These are used by the Huntress support team when troubleshooting.
107-
$ScriptVersion = "Version 2, major revision 8, 2025 Nov 19"
107+
$ScriptVersion = "Version 2, major revision 8, 2025 Nov 20"
108108
$ScriptType = "PowerShell (Datto)"
109109

110110
# variables used throughout this script
@@ -726,7 +726,7 @@ function uninstallHuntress {
726726
# if Huntress services still exist, then delete
727727
$services = @("HuntressRio", "HuntressAgent", "HuntressUpdater", "Huntmon")
728728
foreach ($service in $services) {
729-
if ( $service ) {
729+
if ( Get-Service -name $service -erroraction SilentlyContinue ) {
730730
LogMessage "Service $($service) detected post uninstall, attempting to remove"
731731
c:\Windows\System32\sc.exe STOP $service
732732
c:\Windows\System32\sc.exe DELETE $service
@@ -801,23 +801,21 @@ function testNetworkConnectivity {
801801

802802
foreach ($URL in $URLs) {
803803
$StatusCode = 0
804-
try
805-
{
804+
try {
806805
$Response = Invoke-WebRequest -Uri $URL -TimeoutSec 5 -ErrorAction Stop -ContentType "text/plain" -UseBasicParsing
807806
# This will only execute if the Invoke-WebRequest is successful.
808807
$StatusCode = $Response.StatusCode
809808

810809
# Convert from bytes, if necessary
811810
if ($Response.Content.GetType() -eq [System.Byte[]]) {
812811
$StrContent = [System.Text.Encoding]::UTF8.GetString($Response.Content)
813-
}else {
812+
} else {
814813
$StrContent = $Response.Content.ToString().Trim()
815814
}
816815

817816
# Remove all newlines from the content
818817
$StrContent = [string]::join("",($StrContent.Split("`n")))
819818

820-
821819
$ContentMatch = $StrContent -eq "96bca0cef10f45a8f7cf68c4485f23a4"
822820
} catch {
823821
LogMessage "Error: $($_.Exception.Message)"
@@ -870,7 +868,8 @@ function logInfo {
870868
LogMessage $(systeminfo)
871869

872870
#LogMessage "Host name: '$env:computerName'"
873-
try { $os = (get-WMiObject -computername $env:computername -Class win32_operatingSystem).caption.Trim()
871+
try {
872+
$os = (Get-CimInstance -computername $env:computername -Class win32_operatingSystem).caption.Trim()
874873
} catch {
875874
LogMessage "WMI issues discovered (computer name query), attempting to fix the repository"
876875
winmgmt -verifyrepository

0 commit comments

Comments
 (0)