简体   繁体   English

在SCCM 2007部署后,PowerShell脚本无法创建桌面快捷方式吗?

[英]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). 我目前正在将Windows 7部署到各种PC上(对于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. 如果在Windows安装后在PowerShell中运行脚本,则脚本可以正常工作,创建应用程序的快捷方式。 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 powershell.exe -ExecutionPolicy绕过-NoLogo -NonInteractive -NoProfile -WindowStyle隐藏-File。\\ AppShortcut.ps1

This is the actual powershell script. 这是实际的powershell脚本。

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

$WshShell = New-Object -ComObject WScript.Shell $ WshShell =新对象-ComObject WScript.Shell

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

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

$Shortcut.TargetPath = $AppLocation $ Shortcut.TargetPath = $ AppLocation

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

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

$Shortcut.Save() $ 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; 我用这个VB脚本创建了它,然后删除了它,然后成功了。我让它在公共资料桌面上创建了图标,所以所有人都拥有了它。

make sure you adjust the target path for 32 bit and 64 bit. 确保将目标路径调整为32位和64位。

@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%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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