简体   繁体   中英

Powershell Script not creating shortcut to desktop after SCCM 2007 deployment?

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()

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%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM