Need some guidance on my script

Kiyomi 0 Reputation points
2023-11-30T01:44:46.4266667+00:00

Hello, i am using PSADTK with intune. I am stump. My goal is to deploy my chart folder with files to this location even if the folder already exist: "C:\Users%Username%\AppData\Roaming\Microsoft\Templates\Charts

My problem is that instead of inserting the folder & files under the user profile it will create a new directory with the computername with the folder and files.

snip

My current powershell script:

$CurrentUserName = $RunAsActiveUser.UserName

if ($CurrentUserName)

{

Copy-File -Path '$dirFiles\Charts' -Destination '$envSystemDrive\Users\$CurrentUserName\AppData\Roaming'

}

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Intune | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 48,026 Reputation points
    2023-11-30T03:06:11.9833333+00:00

    You're using single quotes around both strings. That disables variable interpolation. The "$" characters are now just part of the literal between the single quotes.

    To fix that, change those single quotes to double-quotes.

    Also, you're missing the colon between "$env" and "SystemDrive".

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.