Powershell CLI command to create a shortcut does not work on some PCs

108 Views Asked by At

I want to use a Powershell command to create a shortcut on the user's desktop. For some users the command works perfectly fine. For others it does not work at all.

Both users for who it works and users for who it doesn't work are on PSVersion 5.1.22621.963. I also checked the Execution Policy of users for who it works and for who it doesn't. Both had either RemoteSigned or Restricted. The windows accounts of either were administrative accounts. Users for who it did not work also ran the batch file which contains the powershell command as CLI as admin and it did not work either.

I have no clue what's causing the command to not work for some of the users.

This is the command ran within the batch file:

for /f "usebackq delims=" %%a in ("%cd%\config files\_temp\path.txt") do if exist "%%a" (
    set "apb=%%a"
    goto localization/shortcut/default
) else (
    if exist "%cd%\config files\_temp\*" del /f /q "%cd%\config files\_temp\*"
    goto setup
)

:localization/shortcut/default
if exist "%userprofile%\Desktop\APB*.lnk" del "%userprofile%\Desktop\APB*.lnk"
copy /y "%cd%\config files\Binaries\fz.ico" "%apb%\Binaries\" >nul
powershell -NoProfile -Command "& {Write-Host creating shortcut...; $s = (New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Desktop\APB.fz.lnk'); $s.TargetPath = (Get-Content '%cd%\config files\_temp\path.txt')+'\Binaries\APB.exe'; $s.Arguments = '-language=1031 -noverifygc'; $s.WorkingDirectory = (Get-Content '%cd%\config files\_temp\path.txt')+'\Binaries\\'; $s.IconLocation = (Get-Content '%cd%\config files\_temp\path.txt')+'\Binaries\fz.ico'; $s.Save()}"
goto localization

I have also previously used a VB Script to create the shortcut. That did not work for those users either.

EDIT 1:

Screenshot of one of the users' console after executing the command.

EDIT 2:

Screenshot of one of the users' console returning an error.

0

There are 0 best solutions below