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.
Post Reply
User avatar
localpct
Posts: 317
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Wed Sep 09, 2015 12:53 pm

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.  
  3. $Shortcut = $WshShell.CreateShortcut("C:\Users\user\TestTeams.lnk")
  4.  
  5. $Shortcut.TargetPath = C:\Users\user\AppData\Local\Microsoft\Teams\Update.exe --processStart "Teams.exe"
  6.  
  7. $Shortcut.Save()
I've tried single quotes around the whole .targetpath line but that also returns the same failure.

jvierra
Posts: 14445
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Creating MS Teams Shortcut

Post by jvierra »

"TargetPath" can only specify the path to a file and no arguments.

User avatar
localpct
Posts: 317
Joined: Wed Sep 09, 2015 12:53 pm

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: 14445
Joined: Tue May 22, 2007 9:57 am
Contact:

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: 317
Joined: Wed Sep 09, 2015 12:53 pm

Re: Creating MS Teams Shortcut

Post by localpct »

Perfect. Extremely grateful.

Post Reply