Bonjour,
Je pense que j'aurais effectué une recherche du user en amont plutôt que de d'utiliser la variable $env:USERPROFILE, j'aurai fait ceci :
(get-wmiobject -Class Win32_Computersystem).Username
Ce morceau va permettre de récupérer l'utilisateur connecté, si vous avez un nom de domaine, vous pouvez remplacer celui-ci exemple :
1 2
|
(get-wmiobject -Class Win32_Computersystem).Username -replace "mondomain/","" |
De cette manière vous récupérer le nom de l'utilisateur, vous n'avez plus qu'à mettre cette commande dans une variable et d'utiliser cette variable dans le chemin :
1 2 3 4 5 6 7 8
|
$user = (get-wmiobject -Class Win32_Computersystem).Username -replace "mondomain/",""
$SourceFileLocation = "$user\Desktop\soft\APps\monapplis.exe"
$ShortcutLocation = "C:\Users\$user\Desktop\monapplis.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $SourceFileLocation
$Shortcut.Save() |
ou bien peut-être essayer ceci :
1 2 3 4 5 6 7 8
|
$user = $env:username
$SourceFileLocation = "$user\Desktop\soft\APps\monapplis.exe"
$ShortcutLocation = "C:\Users\$user\Desktop\monapplis.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $SourceFileLocation
$Shortcut.Save() |
Partager