0
votes

I am currently in the process of deploying Windows 7 to a variety of PCs (Very new to powershell). The deployment its self is successful, however throughout the task sequence there is a specific step in which a shortcut must be created. After the deployment is complete there is no error or issue to say that the script had not been successful yet, it clearly has not worked. The shortcut is located on a server, but the step within the task sequence is run with the network administrator account, so I doubt it is a permission issue. If you run the script within PowerShell once Windows is installed it works correctly creating the shortcut to the application. If anyone has had a similar experience or any information which may help then I'd appreciate your input.

This is the command line sequence that is used within the task sequence:

powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File .\AppShortcut.ps1

This is the actual powershell script.

$AppLocation = "\PROGRAM\Testprogram\TestApp\App.exe"

$WshShell = New-Object -ComObject WScript.Shell

$desktop = $wshShell.SpecialFolders.Item("AllUsersDesktop")

$Shortcut = $WshShell.CreateShortcut($desktop + "\App.lnk")

$Shortcut.TargetPath = $AppLocation

$Shortcut.IconLocation = "\PROGRAM\Testprogram\TestApp\App.exe"

$Shortcut.WorkingDirectory ="\PROGRAM\Testprogram\TestApp\"

$Shortcut.Save()

1
Why not deploy the shortcut using group policy? - Bill_Stewart
Not sure how well \PROGRAM\Testprogram\TestApp\App.exe would work in a SCCM deployment. Do you get different results if you explicitly use the path C:\PROGRAM\Testprogram\TestApp\ . Running it inside the context of Windows could produce different results. ALso what is the Current Directory when the script is called? .\AppShortcut.ps1 might not be pointing to your script. Are you sure the script is even running at all? - Matt
Sorry for the late reply, I have been away! I will try explicitly enter the path for the shortcut, else I think Group Policy will be the way to go, not sure whether it's worth editing too much in the script to get it working if you can just do it via GP. I will keep you updated, thanks for your help! - Wigleys_Extra

1 Answers

0
votes

I needed to silently deploy an application to all users without the desktop icon then at a later date enable the shortcut icon for use by users.

I used this VB script that created it then delete itself and it did the trick, I had it create the icon on the public profile desktop so all had it;

make sure you adjust the target path for 32 bit and 64 bit.

@echo off

set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"

echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "%PUBLIC%\Desktop\<name of link>.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "<full path to your application that the icon is from>" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%

cscript /nologo %SCRIPT%
del %SCRIPT%