[{"data":1,"prerenderedAt":113},["ShallowReactive",2],{"/2026/01/04-userprofile-environment-variable-resolves-to-systemprofile-via-aws-systems-manager":3},{"id":4,"title":5,"body":6,"date":104,"description":97,"extension":105,"meta":106,"navigation":107,"path":108,"robots":109,"seo":110,"stem":111,"__hash__":112},"posts/2026/01/04 USERPROFILE-environment-variable-resolves-to-systemprofile-via-AWS-Systems-Manager.md","04 USERPROFILE Environment Variable Resolves To Systemprofile Via AWS Systems Manager",{"type":7,"value":8,"toc":101},"minimark",[9,18,25,28,31,33,36,38,50,52,60,62,65,67,70,72,75,77,80,82,85,98],[10,11,13],"post-title",{":date":12},"date",[14,15,17],"h1",{"id":16},"userprofile-environment-variable-resolves-to-cwindowssystem32configsystemprofile-via-aws-systems-manager","USERPROFILE Environment Variable Resolves to C:\\windows\\system32\\config\\systemprofile via AWS Systems Manager",[19,20,21],"notes",{},[22,23,24],"p",{},"This is a repost from my old blog. First posted in 2/15/2021.",[26,27],"br",{},[22,29,30],{},"Context is important which is why different environment can and will produce different values. This time it happened when I ran a PowerShell script through AWS Systems Manager (SSM).",[26,32],{},[22,34,35],{},"I intended to download a file reliably to Downloads directory through PowerShell script and AWS Systems Manager.",[26,37],{},[22,39,40,41,49],{},"At first, it seems straight forward, SSM Agent usually runs as ssm-user with administrator privilege. And USERPROFILE environment variable usually resolves to ",[42,43,48],"code",{"className":44},[45,46,47],"bg-gray-200","p-2","rounded","C:\\Users\\\u003Cusername>",", well, at least locally. So, $env:USERPROFILE\\Downloads should work as intended.",[26,51],{},[22,53,54,55,59],{},"But it isn't so in my particular case. Instead, it resolves to ",[42,56,58],{"className":57},[45,46,47],"C:\\windows\\system32\\config\\systemprofile\\Downloads"," which of course doesn't exist and failed.",[26,61],{},[22,63,64],{},"I also tried using $HOME and it resolves to the same path as $env:USERPROFILE.",[26,66],{},[22,68,69],{},"Reading online, there are indicators that it happened on some machines and not the others. And also, this behavior has been around for a while.",[26,71],{},[22,73,74],{},"Some solutions online suggest tweaking the registry but in my case, I'd rather not do that which might complicate the issue further.",[26,76],{},[22,78,79],{},"And some solutions suggest using the Public user folder and another option is to use ProgramData folder. Both options are not very clear for my use case.",[26,81],{},[22,83,84],{},"In the end, I decided to use and create a custom directory if it doesn't exist using the following script:",[86,87,88],"code-block",{},[89,90,95],"pre",{"className":91,"code":93,"language":94},[92],"language-text","$DownloadDirectory=\"C:\\temp\"\nif (!(Test-Path $DownloadDirectory)) {\n    New-Item -ItemType directory -Path $DownloadDirectory\n}\n","text",[42,96,93],{"__ignoreMap":97},"",[22,99,100],{},"Of course, it will fail if somehow the SSM agent doesn't have permission to create a directory, but in my case, this is acceptable.",{"title":97,"searchDepth":102,"depth":102,"links":103},2,[],"2026-01-04T00:00:00.000Z","md",{},true,"/2026/01/04-userprofile-environment-variable-resolves-to-systemprofile-via-aws-systems-manager",null,{"title":5,"description":97},"2026/01/04 USERPROFILE-environment-variable-resolves-to-systemprofile-via-AWS-Systems-Manager","AuWqkCw2HDHFhcDr5C-5PpVtTa59_NcNJ1hL_yNUqW0",1785167451950]