Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
localpct
Posts: 320 Joined: Wed Sep 09, 2015 12:53 pm
Post
by localpct » Fri Jun 19, 2020 11:29 am
Hello,
I'm noticing a few users don't have the shortcut for teams on their desktop but the app is installed. There a are a few of them, but it's annoying to just remote in and create a shortcut for them manually. I was looking for a way to do this in PSS and a form.
The problem I'm getting is when I create the shortcut, I recieve the error "Value does not fall within the expected range."
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell .CreateShortcut( "C:\Users\user\TestTeams.lnk" )
$Shortcut .TargetPath = C:\Users\user\AppData\Local \Microsoft\Teams\Update.exe -- processStart "Teams.exe"
$Shortcut .Save( )
I've tried single quotes around the whole .targetpath line but that also returns the same failure.
jvierra
Posts: 14691 Joined: Tue May 22, 2007 9:57 am
Answers: 7
Has voted: 2 times
Been upvoted: 5 times
Post
by jvierra » Fri Jun 19, 2020 12:35 pm
"TargetPath" can only specify the path to a file and no arguments.
localpct
Posts: 320 Joined: Wed Sep 09, 2015 12:53 pm
Post
by localpct » Fri Jun 19, 2020 1:29 pm
But it's odd because I can do it manually with right click, create shortcut and paste in the exact string and it works just fine
jvierra
Posts: 14691 Joined: Tue May 22, 2007 9:57 am
Answers: 7
Has voted: 2 times
Been upvoted: 5 times
Post
by jvierra » Fri Jun 19, 2020 2:27 pm
The wizard hides all things difficult for human masters. You need to think like a computer to understand these secrets of the electron.
The following will confuse you a bit more but try it anyway.
Code: Select all
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut('C:\Users\user\TestTeams.lnk')
$Shortcut.TargetPath = 'C:\Users\user\AppData\Local\Microsoft\Teams\Update.exe'
$Shortcut.Arguments = '--processStart Teams.exe'
$Shortcut.Save()
localpct
Posts: 320 Joined: Wed Sep 09, 2015 12:53 pm
Post
by localpct » Fri Jun 19, 2020 9:43 pm
Perfect. Extremely grateful.