src/management/Start-MKPowerShell.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using module .\..\module\manifest\Get-ManifestKey.ps1
using module .\..\events\Register-Shutdown.ps1

$script:ConfigFileParentPath
$script:ImportedSessionHistories

# NoExport: Start-MKPowerShell
function Start-MKPowerShell {
    [CmdletBinding(PositionalBinding = $false)]
    Param(
        [Parameter(Mandatory = $false)]
        [String]$ConfigFilePath
    )

    begin {
        # Environment var to reference this module's directory
        Set-Variable -Name PowerBoltPATH -Value ($script:PSScriptRoot) -Scope Global

        # Start-MKPowerShell may be called directly which may have a nothing value other then MKPowerShellConfigFilePath
        if ($ConfigFilePath) {
            $script:MKPowerShellConfigFilePath = $ConfigFilePath
        }
        else {
            $ConfigFilePath = $script:MKPowerShellConfigFilePath
        }
    }

    end {
        if ((Test-Path -Path $ConfigFilePath) -eq $false) {
            $script:ConfigFileParentPath = $(Split-Path $ConfigFilePath -Parent)
            if ((Test-Path -Path $script:ConfigFileParentPath) -eq $false) {
                New-Item -Path $script:ConfigFileParentPath -ItemType Directory -Verbose
            }
            
            Copy-Item -Path "$PSScriptRoot\..\..\resources\PowerBolt-config.json" -Destination $script:ConfigFileParentPath -Verbose -PassThru
        }
        else {
            $script:ConfigFileParentPath = (Split-Path $ConfigFilePath -Parent)
        }
        
        # Register-Shutdown
    }
}