title: Powershell, URL shortcut
body: <p>I've got a problem and i need your help. I'm trying to do a shortcut from the active URL. I tried a few things and got to this.</p>
  
  <pre><code>Param([switch]$Full, [switch]$Location, [switch]$Content)
  $urls = (New-Object -ComObject Shell.Application).Windows() |
  Where-Object {$_.LocationUrl -match "(^https?://.+)|(^ftp://)"} |
  Where-Object {$_.LocationUrl}
  if($Full)
  {
      $urls
  }
  elseif($Location)
  {
      $urls | select Location*
  }
  elseif($Content)
  {
      $urls | ForEach-Object {
          $ie.LocationName;
          $ie.LocationUrl;
          $_.Document.body.innerText
      }
  }
  else
  {
      $urls | ForEach-Object {$_.LocationUrl}
  }
  $Shortcut = $WshShell.CreateShortcut("E:\Powershell\Ziel\short.lnk")
  $Shortcut.TargetPath = "$urls"
  $Shortcut.Save()
  </code></pre>
  
  <p>But i get an shortcut which makes no sense. What do i do wrong? I'm happy about any suggestion.</p>
  
  <p>I tried now doing it like this:</p>
  
  <pre><code>Param([switch]$Full, [switch]$Location, [switch]$Content)
  $urls = (New-Object -ComObject Shell.Application).Windows() |
  Where-Object {$_.LocationUrl -match "(^https?://.+)|(^ftp://)"} |
  Where-Object {$_.LocationUrl}
  if($Full)
  {
      $urls
  }
  elseif($Location)
  {
      $urls | select Location*
  }
  elseif($Content)
  {
      $urls | ForEach-Object {
          $ie.LocationName;
          $ie.LocationUrl;
          $_.Document.body.innerText
      }
  }
  else
  {
      $urls | ForEach-Object {$_.LocationUrl}
  }
  
  $url = $urls | ForEach-Object {$_.LocationUrl} | select -First 1
  $Shortcut = $WshShell.CreateShortcut("E:\Powershell\Ziel\short.lnk")
  $Shortcut.TargetPath = $url
  $Shortcut.Save()
  </code></pre>
  
  <p>But no it tells me that "$Shortcut = $WshShell.CreateShortcut("E:\Powershell\Ziel\short.lnk")" has the value NULL. I mean, how is that even possible. I don't get it. Please help.</p>