Logonme.Management.PowerShell.psm1

function Get-LogonmeVersionFromModulePath {
    $v = (Split-Path -Path $PSScriptRoot -Leaf)
    try {
        $version = [Version]::Parse($v)
        return [string]$version
    }
    catch {
        $defaultVersion = "latest"
        Write-Host "Failed to parse version string '$v', defaulting to '$defaultVersion'" -ForegroundColor Yellow
        return $defaultVersion
    }
}

$module = $MyInvocation.MyCommand
$env:LogonmeModuleFile = (Join-Path -Path $PSScriptRoot -ChildPath $module.Name)
$env:LogonmeVersion = (Get-LogonmeVersionFromModulePath)

Write-Host " _ " -ForegroundColor Red
Write-Host "| | " -ForegroundColor Red
Write-Host "| | ___ __ _ ___ _ __ _ __ ___ ___ " -ForegroundColor Red
Write-Host "| | / _ \ / _``` |/ _ \| '_ \ | '_ ``` _ \ / _ \" -ForegroundColor Red
Write-Host "| |___| (_) | (_| | (_) | | | |_| | | | | | __/" -ForegroundColor Red
Write-Host "|______\___/ \__, |\___/|_| |_(_)_| |_| |_|\___|" -ForegroundColor Red
Write-Host " __/ | " -ForegroundColor Red
Write-Host " |___/ " -ForegroundColor Red
Write-Host ""
Write-Host "Importing Logon.me PowerShell Module '$env:LogonmeModuleFile ($env:LogonmeVersion)'"
Write-Host ""
Write-Host "== Get API client ==" -ForegroundColor Green
Write-Host "`$client = Get-LogonmeApiClient" -ForegroundColor Blue
Write-Host ""
Write-Host "== Create a local Docker compose file from template ==" -ForegroundColor Green
Write-Host "Get-LogonmeDockerComposeFile | Out-File docker-compose.yml" -ForegroundColor Blue
Write-Host ""
Write-Host "== Setup a new system (Development) ==" -ForegroundColor Green
Write-Host "Invoke-LogonmeSetup -ApiClient `$client -Operation SeedConfiguration" -ForegroundColor Blue
Write-Host ""
Write-Host "== Setup a new system (Docker) ==" -ForegroundColor Green
Write-Host "Invoke-LogonmeSetup -ApiClient `$client -Operation SeedConfiguration -Environment Docker" -ForegroundColor Blue
Write-Host ""
Write-Host "== Verify/reload changed configurations ==" -ForegroundColor Green
Write-Host "Invoke-LogonmeSetup -ApiClient `$client -Operation VerifyConfiguration" -ForegroundColor Blue
Write-Host "Invoke-LogonmeSetup -ApiClient `$client -Operation ClearConfigurationCache" -ForegroundColor Blue
Write-Host ""
Write-Host "== Get system versions (backend/frontend) == " -ForegroundColor Green
Write-Host "Get-LogonmeVersion -ApiClient `$client" -ForegroundColor Blue
Write-Host ""
Write-Host "== Get all config config objects of a type ==" -ForegroundColor Green
Write-Host "Get-LogonmeConfig -ApiClient `$client -ConfigType FormsMethodBankID" -ForegroundColor Blue
Write-Host ""
Write-Host "== Create config object ==" -ForegroundColor Green
Write-Host "`$cfg = Add-LogonmeConfig -ApiClient `$client -ConfigType FormsMethodBankID -Id `'bankid1234`'" -ForegroundColor Blue
Write-Host "`$cfg.displayName = `"MyNewConfiguration1234`"" -ForegroundColor Blue
Write-Host "`$cfg | Set-LogonmeConfig -ApiClient `$client" -ForegroundColor Blue 
Write-Host ""
Write-Host "== Update config object ==" -ForegroundColor Green
Write-Host "`$cfg = Get-LogonmeConfig -ApiClient `$client -ConfigType FormsMethodBankID -OdataFilter `"id eq `'bankid1234`'`"" -ForegroundColor Blue 
Write-Host "`$cfg.description = `"Updated description`"" -ForegroundColor Blue
Write-Host "`$cfg | Set-LogonmeConfig -ApiClient `$client" -ForegroundColor Blue 
Write-Host ""
Write-Host "== Delete config object ==" -ForegroundColor Green
Write-Host "`$cfg = Get-LogonmeConfig -ApiClient `$client -ConfigType FormsMethodBankID -OdataFilter `"id eq `'bankid1234`'`"" -ForegroundColor Blue 
Write-Host "`$cfg | Remove-LogonmeConfig -ApiClient `$client" -ForegroundColor Blue 
Write-Host ""
Write-Host "== Find users by username, email or mobile phone ==" -ForegroundColor Green
Write-Host "Find-LogonmeUsers -ApiClient `$client -Login `"username1`"" -ForegroundColor Blue
Write-Host "Find-LogonmeUsers -ApiClient `$client -Login `"first.last@domain.com`"" -ForegroundColor Blue
Write-Host "Find-LogonmeUsers -ApiClient `$client -Login `"+46123456789`"" -ForegroundColor Blue
Write-Host ""
Write-Host "== Getting user roles ==" -ForegroundColor Green
Write-Host "Get-LogonmeUserData -ApiClient `$client -Login `"username1`" -DataType Roles" -ForegroundColor Blue
Write-Host ""
Write-Host "== Adding a user role named 'role1' ==" -ForegroundColor Green
Write-Host "Add-LogonmeUserRole -ApiClient `$client -Login `"first.last@domain.com`" -Name `"role1`"" -ForegroundColor Blue
Write-Host ""
Write-Host "== Removing all user roles named 'role1' ==" -ForegroundColor Green
Write-Host "`$rolesToDelete = Get-LogonmeUserData -ApiClient `$client -Login `"first.last@domain.com`" -DataType Roles | Where-Object { `$`_.name -eq `"role1`" }" -ForegroundColor Blue
Write-Host "`$rolesToDelete | ForEach-Object { Remove-LogonmeData -ApiClient `$client -Object `$_ }" -ForegroundColor Blue
Write-Host ""
Write-Host "== Syncing external users into Logon.me (requires configured sync client) ==" -ForegroundColor Green
Write-Host "Sync-LogonmeUsers -ApiClient `$client -Username `"username1`"" -ForegroundColor Blue
Write-Host "Sync-LogonmeUsers -ApiClient `$client -ImportFile `"c:\temp\users.txt`"" -ForegroundColor Blue
Write-Host ""