Get-MBSAgent.psm1

<#
.SYNOPSIS
    Get MBS agent parameters (version 0.2.1)
.DESCRIPTION
    Gets the information about MBS agent settings, paths, etc. The function pulls the registry values of the installed MBS backup agent and parses additional values.
.EXAMPLE
    Get-MBSAgent
    Lists all of the parameters on the system into an object
.INPUTS
    None.
.OUTPUTS
    Properties: UninstallKey, FullPath, CBBPath, CBBName, CBBCLIPath, CBBProgramData, (other registry values from path UninstallKey)
.NOTES
    The properties from registry path UninstallKey are fetched dynamically. If the software will add new keys, they can be listed by the function.
#>


Function Get-MBSAgent {
    
    if (((Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{07BCB989-197A-4E3D-852D-DE8363860401}" -Name "UninstallKey" -ErrorAction SilentlyContinue).'UninstallKey') -eq $null) {
        Write-Error "ERROR: MSP360 Online backup agent is not installed on this machine."
        return $false
    }

    $UninstallKey = (Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{07BCB989-197A-4E3D-852D-DE8363860401}" -Name "UninstallKey")."UninstallKey"
    $UninstallPath = Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{07BCB989-197A-4E3D-852D-DE8363860401}"
    $FullPath = (Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\$UninstallKey" -Name "(default)")."(default)"
    $RegistryEntries = Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\$UninstallKey"
    $CBBPath = $FullPath.Substring(0, $FullPath.LastIndexOf('\'))
    $CBBName = $FullPath.Substring($CBBPath.Length+1) -replace ".{4}$"
    $CBBCompany = $RegistryEntries.Publisher
    $CBBCLIPath = $CBBPath+"\cbb.exe"
    
    if (Test-Path -Path "$env:ProgramData\Online Backup\enginesettings.list") {
        $CBBProgramData = "$env:ProgramData\Online Backup"
    }
    elseif (Test-Path -Path "$env:ProgramData\$CBBCompany\enginesettings.list") {
        $CBBProgramData = "$env:ProgramData\$CBBCompany"
    } else {
        Write-Error "ERROR: The folder with backup agent settings not found"
        return $false
    }

    $MBSAgent = New-Object -TypeName psobject
    $MBSAgent | Add-Member -MemberType NoteProperty -Name UninstallKey -Value $UninstallKey
    $UninstallPath | Get-Member -MemberType NoteProperty | ForEach-Object {
        if (($_.Name -ne "UninstallKey") -And ($_.Name -ne "(default)") -And ($_.Name -ne "PSChildName") -And ($_.Name -ne "PSParentPath") -And ($_.Name -ne "PSPath") -And ($_.Name -ne "PSProvider")) {
            $PropertyName = $_.Name
            $MBSAgent | Add-Member -MemberType NoteProperty -Name $PropertyName -Value $UninstallPath.$PropertyName
        }
    }
    $MBSAgent | Add-Member -MemberType NoteProperty -Name FullPath -Value $FullPath
    $RegistryEntries | Get-Member -MemberType NoteProperty | ForEach-Object {
        if (($_.Name -ne "(default)") -And ($_.Name -ne "PSChildName") -And ($_.Name -ne "PSParentPath") -And ($_.Name -ne "PSPath") -And ($_.Name -ne "PSProvider")) {
            $PropertyName = $_.Name
            $MBSAgent | Add-Member -MemberType NoteProperty -Name $PropertyName -Value $RegistryEntries.$PropertyName
        }
    }
    $MBSAgent | Add-Member -MemberType NoteProperty -Name CBBPath -Value $CBBPath
    $MBSAgent | Add-Member -MemberType NoteProperty -Name CBBName -Value $CBBName
    $MBSAgent | Add-Member -MemberType NoteProperty -Name CBBCLIPath -Value $CBBCLIPath
    $MBSAgent | Add-Member -MemberType NoteProperty -Name CBBProgramData -Value $CBBProgramData
    
    $MBSAgent
}

Set-Alias gma Get-MBSAgent
Export-ModuleMember -Function 'Get-*' -Alias gma