Invoke-RemoteApp.psm1

<#
    .DESCRIPTION
        Invoke-RemoteApp initializes a Remote session in Remote Application Mode.
    .SYNOPSIS
        Launches Remote App on specified System.
    .PARAMETER ComputerName
        ComputerName or IP Address of Remote Machine
    .PARAMETER UserName
        Username, format (Domain\UserName)
    .PARAMETER Path
        Specify Remote Path for Executable
    .PARAMETER Arguments
        Add Comandline Paramter for Application
    .EXAMPLE
        Invoke-RemoteApp -ComputerName 10.10.10.20 -UserName Admin -Path shell:appsFolder
    .EXAMPLE
        Invoke-RemoteApp -ComputerName 10.30.10.10 -UserName TDH.LAB\Administrator -Path C:\Windows\System32\MMC.exe -Arguments C:\persistent\View.msc
    .EXAMPLE
        Invoke-RemoteApp -ComputerName 192.168.10.20 -UserName Test\Admin -Path wt.exe -Arguments "-M --window 3"
#>

#Invoke-RemoveApp v3
function Invoke-RemoteApp {

    param (
        #ComputerName
        [Parameter(Mandatory=$true,
        Position=0,
        ValueFromPipeline=$true,
        HelpMessage="Computer Name or Address")]
        [Alias("H")]
        [string]$ComputerName,

        #Credential
        [Parameter(Mandatory=$true,
        Position=1,
        ValueFromPipeline=$true,
        HelpMessage="Domain\Username")]
        [Alias("C")]
        [string]$UserName,

        #Remote Path
        [Parameter(Mandatory=$true,
        Position=2,
        ValueFromPipeline=$true,
        HelpMessage="Remote path to executable")]
        [Alias("P")]
        [string]$Path,

        #Arguments
        [Parameter(Mandatory=$false,
        Position=3,
        ValueFromPipeline=$true,
        HelpMessage="Arguments for Remote Executable")]
        [Alias("A")]
        [string]$Arguments
    )

    $DomainName = Split-Path $UserName
    $RemAppName = Split-Path -Path $Path -Leaf
    #RDP File for mstsc
    $RDPFile = "
    full address:s:$ComputerName
    server port:i:3389
 
    username:s:$UserName
    domain:s:$DomainName
    authentication level:i:2
    negotiate security layer:i:1
    enablecredsspsupport:i:1
    prompt for credentials:i:0
 
    enableworkspacereconnect:i:0
    autoreconnect max retries:i:5
 
    remoteapplicationmode:i:1
    remoteapplicationname:s:$RemAppName
    remoteapplicationprogram:s:$Path
    remoteapplicationcmdline:s:$Arguments
 
    gatewayusagemethod:i:4
    gatewaycredentialssource:i:4
    "

    Write-Debug $RDPFile
    #Create RDP File
    [string]$RDPFilePath = (New-Item -Path "$env:temp\" -Name "0762c730-5cd5-420f-a1ee-83cfe05124a6.rdp" -Value $RDPFile -Force).FullName
    Write-Debug $RDPFilePath
    mstsc.exe $RDPFilePath
}
Export-ModuleMember -Function Invoke-RemoteApp