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

Suggestion for PowerShell install script maintainability #67

Open
alexipeck opened this issue Dec 11, 2023 · 2 comments
Open

Suggestion for PowerShell install script maintainability #67

alexipeck opened this issue Dec 11, 2023 · 2 comments

Comments

@alexipeck
Copy link

alexipeck commented Dec 11, 2023

In the current v2 install script, I see that it gets the latest installer versions via consistent URLs.
If you want the entire script to be more maintainable without clients needing to update the install script itself in their respective deployed environments and considering that you have already split it out into many functions, it may be worth setting up a PowerShell module, containing all these functions within a .psm1 file with added version control of some kind to reduce the network load.
This would allow you to significantly shorten/simplify the install script, leaving only end-user modification of AccountKey, OrganizationKey, TagsKey, DebugPreference and timeout.
Values like estimatedSpaceNeeded could be maintained yourself within the module based on the current installer version.

I have included a short example for importing a module directly from GitHub (this function is adapted from my more generic module import function and doesn't necessarily handle the install location as you may want to)

$modulePath = Join-Path -Path $env:PSModulePath.Split(';')[0] -ChildPath "HuntressInstallerModule"
if (-not (Test-Path -Path $modulePath)) { New-Item -ItemType Directory -Path $modulePath | Out-Null }
$moduleFilePath = Join-Path -Path $modulePath -ChildPath "HuntressInstallerModule.psm1"
try {
    Invoke-WebRequest -Uri "https://raw.githubusercontent.com/huntresslabs/deployment-scripts/main/HuntressInstallerModule.psm1" -OutFile $moduleFilePath -ErrorAction Stop
    & { $WarningPreference = 'SilentlyContinue'; Import-Module -Name $moduleFilePath -ErrorAction Stop }
    Write-Host "Imported module 'HuntressInstallModule' successfully."
} catch {
    Write-Host "Error: Required module HuntressInstallerModule could not be downloaded or installed: $($_.Exception.Message). Exiting"
    exit 1
}
@deborahjones-huntress
Copy link

Open a ticket in Shortcut
https://app.shortcut.com/huntress/story/117836

@alexipeck
Copy link
Author

Open a ticket in Shortcut https://app.shortcut.com/huntress/story/117836

I'm guessing Shortcut is only available to your internal team. I don't have access to this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants