You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过PowerShell创建MyDocuments快捷方式的Azure Intune执行异常问题

Fix: Intune Script Creates Shortcut to "This PC" Instead of MyDocuments

The issue occurs because when your script runs via Azure Intune, it executes in the SYSTEM account context, not the end user's context. The [environment]::GetFolderPath('MyDocuments') cmdlet returns the Documents folder of the SYSTEM account (located at C:\Windows\System32\config\systemprofile\Documents), which isn't visible to regular users—so File Explorer redirects this to "This PC" when accessed.

To resolve this, you need to create a shortcut that dynamically points to the current user's Documents folder regardless of who clicks it. The best way to do this is using Windows' special shell folder path shell:Personal, which automatically resolves to the logged-in user's Documents directory (even if it's redirected to OneDrive or a network share).

Here's the corrected script:

# Define the shortcut path in the Public Desktop (visible to all users)
$ShortcutPath = "$env:Public\Desktop\Docu.lnk"

# Create the WScript Shell object
$WshShell = New-Object -ComObject WScript.Shell

# Create the shortcut
$Shortcut = $WshShell.CreateShortcut($ShortcutPath)

# Use shell:Personal to target the current user's Documents folder
$Shortcut.TargetPath = "shell:Personal"

# Save the shortcut
$Shortcut.Save()

Why this works:

  • shell:Personal is a shell namespace path that Windows interprets per-user. When any user clicks the shortcut, Windows resolves it to their own Documents folder, not the SYSTEM account's.
  • This approach is more reliable than hardcoding paths because it adapts to any folder redirection or custom locations the user might have set.

Additional Notes:

  • If you need to create the shortcut only for specific users (instead of all users), replace $env:Public\Desktop with the target user's desktop path. However, since Intune runs as SYSTEM, you'd need to first retrieve the user's profile path (e.g., via querying the registry for their SID).
  • Always test the script in a virtual machine or test environment before deploying it to production via Intune.

内容的提问来源于stack exchange,提问作者G.Arefin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:17:16