Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Write-Output with unsupported parameters #106

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions Datto-RMM/scripts/InstallHuntress.dattormm.comstore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,16 @@ function Test-Parameters {
if ($AccountKey -eq "__ACCOUNT_KEY__") {
$err = "AccountKey not set! Suggest using the -acctkey flag followed by your account key (you can find it in the Downloads section of your Huntress portal)."
LogMessage $err
Write-Output $err -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err
exit 1
} elseif ($AccountKey.length -ne 32) {
$err = "Invalid AccountKey specified (incorrect length)! Suggest double checking the key was copy/pasted in its entirety"
LogMessage $err
Write-Output $err -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err
exit 1
} elseif (($AccountKey -match '[^a-zA-Z0-9]')) {
$err = "Invalid AccountKey specified (invalid characters found)! Suggest double checking the key was copy/pasted fully"
LogMessage $err
Write-Output $err -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err
exit 1
}
Expand All @@ -209,13 +206,11 @@ function Test-Parameters {
if ($OrganizationKey -eq "__ORGANIZATION_KEY__") {
$err = "OrganizationKey not specified! This is a user defined identifier set by you (usually your customer's organization name)"
LogMessage $err
Write-Output $err -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err
exit 1
} elseif ($OrganizationKey.length -lt 1) {
$err = "Invalid OrganizationKey specified (length should be > 0)!"
LogMessage $err
Write-Output $err -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err
exit 1
}
Expand Down Expand Up @@ -293,7 +288,6 @@ function verifyInstaller ($file) {
"Suggest trying again, contact [email protected] if it fails >2 times")
LogMessage $err
LogMessage $SupportMessage
Write-Output $err -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err + " " + $SupportMessage
}
}
Expand All @@ -304,7 +298,7 @@ function prepareAgentPath {
if (Test-Path $path -PathType Leaf) {
$backup = "$path.bak"
$err = "WARNING: '$path' already exists and is not a directory, renaming to '$backup'."
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage $err
Rename-Item -Path $path -NewName $backup -Force
}
}
Expand Down Expand Up @@ -383,7 +377,6 @@ function Install-Huntress ($OrganizationKey) {
"your logs. If the issue continues to occur, please send the log to the Huntress " +
"Team for help at [email protected]")
LogMessage $msg
Write-Output $msg -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err + " " + $SupportMessage
}

Expand All @@ -404,7 +397,6 @@ function Install-Huntress ($OrganizationKey) {
} catch {
$process | Stop-Process -Force
$err = "ERROR: Installer failed to complete in $timeout seconds. Possible interference from a security product?"
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage $err
LogMessage $SupportMessage
throw $ScriptFailed + " " + $err + " " + $SupportMessage
Expand Down Expand Up @@ -442,7 +434,6 @@ function Test-Installation {
}
if ( ! $didAgentRegister) {
$err = "WARNING: It does not appear the agent has successfully registered. Check 3rd party AV exclusion lists to ensure Huntress is excluded."
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage ($err + $SupportMessage)
}

Expand Down Expand Up @@ -598,7 +589,6 @@ function checkFreeDiskSpace {
$freeSpaceNice = $freeSpace.ToString('N0')
if ($freeSpace -lt $estimatedSpaceNeeded) {
$err = "Low disk space detected, you may have troubles completing this install. Only $($freeSpaceNice) bytes remaining (need about $($estimatedSpaceNeeded.ToString('N0'))."
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage $err
} else {
LogMessage "Free disk space: $($freeSpaceNice)"
Expand Down Expand Up @@ -636,7 +626,6 @@ function runProcess ($process, $flags, $name){
}

$err = "ERROR: $($name) running as '$($process) $($flags)' failed to complete in $timeout seconds, full error message: '$($msg).'"
Write-Host $err -ForegroundColor white -BackgroundColor red
LogMessage $err
copyLogAndExit
}
Expand Down Expand Up @@ -677,7 +666,6 @@ function uninstallHuntress {
}
} else {
$err = "Note: unable to find Huntress install folder. Attempting to manually uninstall."
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage $err
}

Expand All @@ -693,7 +681,6 @@ function uninstallHuntress {
if ($i -eq 15) {
$err = "Uninstall not complete after $($i) seconds"
LogMessage $err
Write-Output $err -ForegroundColor white -BackgroundColor red
}
}
}
Expand Down Expand Up @@ -770,18 +757,16 @@ function testNetworkConnectivity {
foreach ($URL in $URLs) {
if (! (Test-NetConnection $URL -Port 443).TcpTestSucceeded) {
$err = "WARNING, connectivity to Huntress URL's is being interrupted. You MUST open port 443 for $($URL) in order for the Huntress agent to function."
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage $err
$connectivityTolerance --
} else {
LogMessage "Connection succeeded to $($URL) on port 443!"
}
}
if ($connectivityTolerance -lt 0) {
Write-Output "Please fix the closed port 443 for the above domains before attempting to install" -ForegroundColor white -BackgroundColor red
LogMessage "Please fix the closed port 443 for the above domains before attempting to install"
$err = "Too many connections failed $($connectivityTolerance), exiting"
LogMessage $err
Write-Output "$($err), $($SupportMessage)" -ForegroundColor white -BackgroundColor red
return $false
}
return $true
Expand Down Expand Up @@ -926,7 +911,6 @@ function main () {
if ( !($reregister)) {
if (isOrphan) {
$err = 'Huntress Agent is orphaned, unable to use the provided flag. Switching to uninstall/reinstall (reregister flag)'
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage "$err"
$reregister = $true
}
Expand Down Expand Up @@ -991,7 +975,7 @@ function main () {
if ( Confirm-ServiceExists($HuntressAgentServiceName) ) {
$err = "The Huntress Agent is already installed. Exiting with no changes. Suggest using -reregister or -reinstall flags"
LogMessage "$err"
Write-Output 'Huntress Agent is already installed. Suggest using the -reregister or -reinstall flags' -ForegroundColor white -BackgroundColor red
LogMessage 'Huntress Agent is already installed. Suggest using the -reregister or -reinstall flags'
copyLogAndExit
}
}
Expand Down
20 changes: 3 additions & 17 deletions Powershell/InstallHuntress.powershellv2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,16 @@ function Test-Parameters {
if ($AccountKey -eq "__ACCOUNT_KEY__") {
$err = "AccountKey not set! Suggest using the -acctkey flag followed by your account key (you can find it in the Downloads section of your Huntress portal)."
LogMessage $err
Write-Output $err -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err
exit 1
} elseif ($AccountKey.length -ne 32) {
$err = "Invalid AccountKey specified (incorrect length)! Suggest double checking the key was copy/pasted in its entirety"
LogMessage $err
Write-Output $err -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err
exit 1
} elseif (($AccountKey -match '[^a-zA-Z0-9]')) {
$err = "Invalid AccountKey specified (invalid characters found)! Suggest double checking the key was copy/pasted fully"
LogMessage $err
Write-Output $err -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err
exit 1
}
Expand All @@ -201,13 +198,11 @@ function Test-Parameters {
if ($OrganizationKey -eq "__ORGANIZATION_KEY__") {
$err = "OrganizationKey not specified! This is a user defined identifier set by you (usually your customer's organization name)"
LogMessage $err
Write-Output $err -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err
exit 1
} elseif ($OrganizationKey.length -lt 1) {
$err = "Invalid OrganizationKey specified (length should be > 0)!"
LogMessage $err
Write-Output $err -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err
exit 1
}
Expand Down Expand Up @@ -285,7 +280,6 @@ function verifyInstaller ($file) {
"Suggest trying again, contact [email protected] if it fails >2 times")
LogMessage $err
LogMessage $SupportMessage
Write-Output $err -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err + " " + $SupportMessage
}
}
Expand All @@ -296,7 +290,7 @@ function prepareAgentPath {
if (Test-Path $path -PathType Leaf) {
$backup = "$path.bak"
$err = "WARNING: '$path' already exists and is not a directory, renaming to '$backup'."
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage $err
Rename-Item -Path $path -NewName $backup -Force
}
}
Expand Down Expand Up @@ -375,7 +369,6 @@ function Install-Huntress ($OrganizationKey) {
"your logs. If the issue continues to occur, please send the log to the Huntress " +
"Team for help at [email protected]")
LogMessage $msg
Write-Output $msg -ForegroundColor white -BackgroundColor red
throw $ScriptFailed + " " + $err + " " + $SupportMessage
}

Expand All @@ -396,7 +389,6 @@ function Install-Huntress ($OrganizationKey) {
} catch {
$process | Stop-Process -Force
$err = "ERROR: Installer failed to complete in $timeout seconds. Possible interference from a security product?"
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage $err
LogMessage $SupportMessage
throw $ScriptFailed + " " + $err + " " + $SupportMessage
Expand Down Expand Up @@ -434,7 +426,6 @@ function Test-Installation {
}
if ( ! $didAgentRegister) {
$err = "WARNING: It does not appear the agent has successfully registered. Check 3rd party AV exclusion lists to ensure Huntress is excluded."
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage ($err + $SupportMessage)
}

Expand Down Expand Up @@ -590,7 +581,6 @@ function checkFreeDiskSpace {
$freeSpaceNice = $freeSpace.ToString('N0')
if ($freeSpace -lt $estimatedSpaceNeeded) {
$err = "Low disk space detected, you may have troubles completing this install. Only $($freeSpaceNice) bytes remaining (need about $($estimatedSpaceNeeded.ToString('N0'))."
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage $err
} else {
LogMessage "Free disk space: $($freeSpaceNice)"
Expand Down Expand Up @@ -628,7 +618,6 @@ function runProcess ($process, $flags, $name){
}

$err = "ERROR: $($name) running as '$($process) $($flags)' failed to complete in $timeout seconds, full error message: '$($msg).'"
Write-Host $err -ForegroundColor white -BackgroundColor red
LogMessage $err
copyLogAndExit
}
Expand Down Expand Up @@ -669,7 +658,6 @@ function uninstallHuntress {
}
} else {
$err = "Note: unable to find Huntress install folder. Attempting to manually uninstall."
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage $err
}

Expand All @@ -685,7 +673,6 @@ function uninstallHuntress {
if ($i -eq 15) {
$err = "Uninstall not complete after $($i) seconds"
LogMessage $err
Write-Output $err -ForegroundColor white -BackgroundColor red
}
}
}
Expand Down Expand Up @@ -808,7 +795,7 @@ function testNetworkConnectivity {
}
}
if ($connectivityTolerance -lt 0) {
Write-Output "Please fix the closed port 443 for the above domains before attempting to install" -ForegroundColor white -BackgroundColor red
LogMessage "Please fix the closed port 443 for the above domains before attempting to install"
$err = "Too many connections failed $($connectivityTolerance), exiting"
LogMessage "$($err), $($SupportMessage)"
return $false
Expand Down Expand Up @@ -944,7 +931,6 @@ function main () {
if ( !($reregister)) {
if (isOrphan) {
$err = 'Huntress Agent is orphaned, unable to use the provided flag. Switching to uninstall/reinstall (reregister flag)'
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage "$err"
$reregister = $true
}
Expand Down Expand Up @@ -1009,7 +995,7 @@ function main () {
if ( Confirm-ServiceExists($HuntressAgentServiceName) ) {
$err = "The Huntress Agent is already installed. Exiting with no changes. Suggest using -reregister or -reinstall flags"
LogMessage "$err"
Write-Output 'Huntress Agent is already installed. Suggest using the -reregister or -reinstall flags' -ForegroundColor white -BackgroundColor red
LogMessage 'Huntress Agent is already installed. Suggest using the -reregister or -reinstall flags'
copyLogAndExit
}
}
Expand Down
Loading