LARSINUS.psm1


function Add-Prefix{
    <#
    .SYNOPSIS
    Adds a line prefix
    .PARAMETER Color
    .PARAMETER InfoType
    .DESCRIPTION
    It will add a prefix that you can use in front of your Write-Host.
    The output is a square brackets with some text (of your choice) between in a color (of your choice)
    .EXAMPLE
    PS C:\Add-Prefix -Color Red -InfoType Error
    [ERROR]
    .EXAMPLE
    PS C:\Add-Prefix -Color Magenta -InfoType Information ; Write-Host 'Hello World!'
    [INFORMATION] Hello World!
    #>

    param (
        [Parameter()]
        #[validateset('Black','DarkBlue','DarkGreen','DarkCyan','DarkRed','DarkMagenta','DarkYellow','Gray','DarkGray','Blue','Green','Cyan','Red','Magenta','Yellow','White')]
        [ConsoleColor]$Color,
        [Parameter()]
        [string]$InfoType
    )
    Write-Host '[' -NoNewline
    Write-Host -ForegroundColor $color ($infoType).ToUpper() -NoNewline
    Write-Host '] ' -noNewline
}

function Add-Space () {
    <#
    .SYNOPSIS
    Adds spaces after previous text block based on that length.
    .PARAMETER TextLength
    .PARAMETER MaxSpace
    .DESCRIPTION
    Used to make sure your columns are aligned correctly when doing Write-Host and the previous text block had different length.
    This will calculate how much space should be added at the end of the previous text block.
    .EXAMPLE
    PS C:\Add-Space -TextLength $String.Length -MaxSpace 25
    #>

    param (
        [Parameter (Mandatory=$true)]
        [int]$TextLength,
        [Parameter (Mandatory=$True)]
        [int]$MaxSpace
    )
    $SpaceToAdd = ($MaxSpace - $TextLength)
    While ($SpaceToAdd -gt 0){
        $Space = $Space + ' '
        $SpaceToAdd--
    }
    Write-Host $Space -NoNewline
}

function Open-File {
    <#
    .SYNOPSIS
    Gets a file.
    .PARAMETER Path
    .DESCRIPTION
    Opens the Windows Explorer so you can browse to a file to be used in your script.
    Can be used together with other functions/cmdlets
    .EXAMPLE
    PS C:\Open-File
    Opens Windows Explorer in the current directory you're in.
    .EXAMPLE
    PS C:\Open-File -Path C:\Users\User1\OneDrive\MyScripts
    .EXAMPLE
    PS C:\$information = Get-Content (Open-File -Path "C:fso") | ConvertFrom-Json
    #>

    param (
        [parameter()]
        $Path = 'C:fso'
    )
    [System.Reflection.Assembly]::LoadWithPartialName(“System.windows.forms”)
    Out-Null
    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $OpenFileDialog.initialDirectory = $Path
    $OpenFileDialog.filter = “All files (*.*)| *.*”
    $OpenFileDialog.ShowDialog() | Out-Null
    $OpenFileDialog.filename
}

function Save-File {
    <#
    .SYNOPSIS
    Saves a file.
    .PARAMETER Path
    .PARAMETER FileDialogFileType
    .DESCRIPTION
    Opens the Windows Explorer so you can browse to where you want to save the file.
    Use the parameter -FileDialogFileType to specify which file type you want the user to be able to save as.
    .EXAMPLE
    PS C:\Save-File -FileDialogFileType *.*
    Opens Windows Explorer in the current directory you're in.
    .EXAMPLE
    PS C:\Save-File -Path C:\Users\User1\OneDrive\Scripts\Logs -FileDialogFileType *.log
    #>

    param (
        [parameter()]
        $Path = 'C:fso',
        [Parameter(Mandatory = $true)]
        [String]$FileDialogFileType
    )
    [System.Reflection.Assembly]::LoadWithPartialName(“System.windows.forms”)
    Out-Null
    $SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
    $SaveFileDialog.initialDirectory = $Path
    $SaveFileDialog.filter = “All files ($FileDialogFileType )| $FileDialogFileType ”
    $result = $SaveFileDialog.ShowDialog()
    if ($result -eq 'OK'){
        Out-File -FilePath $SaveFileDialog.filename -InputObject $arrCollections
    }
}

function Enable-Sideloading {
    <#
        .SYNOPSIS
        Enables Sidelaoding of apps
        .DESCRIPTION
        ---[ MUST BE RUN WITH ELEVATED PRIVILEGES ]---
        Enables sideloading of applications in Windows 10.
        Being used to allow installations of custom/LOB .msix packaged apps.
        Since they are not published to the Microsoft Store, we need to enable sideloading.
        They are secured by using certificates.
        .EXAMPLE
        PS C:\Enable-Sideloading.ps1
        #>


        $registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
        $Name1 = "AllowAllTrustedApps"
        $value1 = "1"
        New-ItemProperty -Path $registryPath -Name $name1 -Value $value1 -PropertyType DWORD -Force

        $Name2 = "AllowDevelopmentWithoutDevLicense"
        $value2 = "0"

        New-ItemProperty -Path $registryPath -Name $name2 -Value $value2 -PropertyType DWORD -Force
    }



Export-ModuleMember -Function Add-Prefix
Export-ModuleMember -Function Add-Space
Export-ModuleMember -Function Open-File
Export-ModuleMember -Function Save-File
Export-ModuleMember -Function Enable-Sideloading