title: Failed to create a shortcut with PowerShell
body: <p>I would like to create a shortcut of a PowerShell script in SendTo folder with PowerShell.<br>
  My script is like below and worked on my laptop, but failed on a PC at workplace.<br>
  <br>
  A possible difference between those two environment is that both the script and SendTo folder are located in a local drive on my laptop while they are on a network drive at office.<br></p>
  <pre><code># Create a WScript object
  $WsShell=New-Object -ComObject WScript.Shell
  
  # Create a shortcut
  $SendToDirectory=Join-Path $env:APPDATA &quot;\Microsoft\Windows\SendTo\test.lnk&quot;
  $Shortcut=$WsShell.CreateShortcut(&quot;$SendToDirectory&quot;)
  
  # Set PowerShell location as a target path
  $PowerShellFullPath=cmd /c where powershell
  $Shortcut.TargetPath=$PowerShellFullPath
  
  # Set arguments to pass to the power shell
  $Shortcut.Arguments=&quot;-NoProfile -ExecutionPolicy Bypass -File `&quot;$PSCommandPath`&quot;&quot;
  
  # Shortcut configuration
  $PowerShellPath=[System.IO.Path]::GetDirectoryName($PowerShellFullPath)
  $Shortcut.WorkingDirectory=$PowerShellPath
  $Shortcut.WindowStyle=1 # 1:Normal/2:Max/7:Min
  
  # Save shortcut
  $Shortcut.Save()
  </code></pre>
  <p>When I failed to create a shortcut on a office PC, no error came up, so I have no idea what is wrong.<br>
  For debugging I ran the below script on PowerShell ISE Console,</p>
  <pre><code>$WsShell=New-Object -ComObject WScript.Shell
  $SendToDirectory=&quot;.test.lnk&quot;
  $Shortcut=$WsShell.CreateShortcut(&quot;$SendToDirectory&quot;)
  </code></pre>
  <p>and then</p>
  <pre><code>$Shortcut
  </code></pre>
  <p>The result was like this (I am replacing the path to ***)</p>
  <pre><code>FullName         : ***\test.lnk
  Arguments        : 
  Description      : 
  Hotkey           : 
  IconLocation     : ,0
  RelativePath     : 
  TargetPath       : 
  WindowStyle      : 1
  WorkingDirectory : 
  </code></pre>
  <p>This indicates that the object is properly created but does not appear on the network drive as intended.</p>
  <p>I would appreciate it if anyone give me a tip to settle this out.</p>
  <p><strong>&lt;Addition on 2 Oct 2020&gt;</strong><br>
  The code runs without an error, but on the folder a shortcut never appears. Also, at the end of the script I added test-path to test the shortcut existence and it showed that the shortcut does not exist. That's why I said &quot;failed to create a shortcut&quot;.</p>