In on-prem scenarios you might want to use Temporary user profiles and still be able to access data on UNC paths on other servers

There are two scenarios:

  1. You map an UNC share with one single user account for all users(pw visible in script or UI variable):
    if (-not (Test-Path S:)) { $username = "mydomain\sa-share" $password = "MyS3cretP@$$word" net use S: \\host\share /persistent:yes /USER:$username $password }
    With this solution the drive is mapped with the same special user for all user sessions. You either have to specify the password in the script like above or create a variable in PowerTags like
    SAPW=MyS3cretP@$$word

    and then in the script above use

    $password = "$env:SAPW"


  2. You map an UNC share per user:
    if (-not (Test-Path S:)) { $cred = Get-Credential "mydomain\$env:USER_SHORTID" net use S: \\host\share /persistent:yes /USER:$($cred.UserName) $cred.GetNetworkCredential().password }
    This opens a Windows login dialog:


Put the following in a script like %ProgramData%\Cameyo\LaunchMyApp.ps1, then add the following to the script:
param ($Command, $Arguments = $null)

# code from above

if ($Arguments -eq $null) {
    Start-Process $Command
} else {
    Start-Process $Command -ArgumentList $Arguments
}


finally start it by starting PowerShell with Parameters in the Command line in the apps UI:

PowerShell.exe
-WindowStyle Minimized -File %ProgramData%\Cameyo\LaunchMyApp.ps1 -Command "C:\Program Files\MyCompany\MyProg.exe" -Arguments "/s"

this will prompt for the credentials above (if necessary) and then start the application:

"C:\Program Files\MyCompany\MyProg.exe" /s


You might wonder why net use is used in a PowerShell script and not New-PSDrive. That is because New-PSDrive is buggy when it comes to persistence and net use just works fine.


After mapping, you can add the mapped drive or path into your Cameyo dialog using the following PowerTag:

!FILEDIALOG_EXTRA=SHARE>0>S:\

see: Cameyo File Dialog