How to deploy a folder to the current user's folder

I am trying to deploy a folder to current users’ documents folder using the win32 app deployment tool to create an intunewin file and then deploy via intune.

I have packaged the following to be converted into an intunewin file:


Below is a couple PSscripts I’ve attempted but keeps failing. Any ideas would be greatly appreciated!

$username = $Env:Username

$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$Source = "$PSScriptRoot\VPN.txt"
$username = $Env:Username
$Destination = "C:\Users\$username\Documents\AWSOOOVPN"

Copy-Item -Path $Source -Destination $Destination -Recurse -Force


$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$Source = "$PSScriptRoot\VPN.txt"
$Destination = "$env:Documents\VPNfolder"

Copy-Item -Path $Source -Destination $Destination -Recurse -Force

Without having experiences with Intune - it might not be an PowerShell issue?! :wink:

$PSScriptRoot is an automatic variable filled in be PowerShell when running a script. You should not use this name for your own variables!! :point_up_2:t4:

Regardless of that unnecessary variable assignment - does the script runs in the current users context? If it runs in system context you cannot use $Env:Username or $env:Documents! :point_up_2:t4:

This is the Install.cmd file:

SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%PSscript.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%'"

This script doesnt run at all. Do you have any suggestions for the correct syntax for the users’ folder?

Do you have to use a CMD file at all? I’d assume that a technology like Intune is able to run a PowerShell script by itself.

If you provide a script file why don’t you provide it with the proper command line argument -File?

It depends pretty much in what context the script runs. Does it have to a particular user or is it actually for ALL users?

Yes it’s for all users.

I need to the install.cmd to intune can all it. You can run scripts in intune, but it will need the folder files which you can’t do unless you packaged the cmd, PScript into an intunewin file.

This is the standard way of deploying via intune: Deploy file to workstations with Microsoft Intune

So why don’t you enumerate all folders in C:\Users and deploy it to all of them? Why would you like to deploy it individually?

Because users only have permission to access their actual folder and nothing outside it. C:\Users is outside their folder permission.

Is Intune not able to run tasks in system context?

But if the script runs in user context anyway the environment variables should work. Have you tried providing the path to the script file with the -File parameter?