Creating MS Teams Shortcut

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.
This topic is 3 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Creating MS Teams Shortcut

Post by localpct »

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."
  1. $WshShell = New-Object -comObject WScript.Shell
  2. $Shortcut = $WshShell.CreateShortcut("C:\Users\user\TestTeams.lnk")
  3. $Shortcut.TargetPath = C:\Users\user\AppData\Local\Microsoft\Teams\Update.exe --processStart "Teams.exe"
  4. $Shortcut.Save()
I've tried single quotes around the whole .targetpath line but that also returns the same failure.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Creating MS Teams Shortcut

Post by jvierra »

"TargetPath" can only specify the path to a file and no arguments.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Creating MS Teams Shortcut

Post by localpct »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Creating MS Teams Shortcut

Post by jvierra »

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()
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Creating MS Teams Shortcut

Post by localpct »

Perfect. Extremely grateful.
This topic is 3 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked