CSV to create URL links – error with saving

Welcome Forums General PowerShell Q&A CSV to create URL links – error with saving

Viewing 1 reply thread
  • Author
    Posts
    • #239777
      Participant
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      Hi all,

      I’m new to powershell and I’m trying to make a folder with shortcuts to websites.
      I have a CSV file with the following format

      Path Name Location
      https://www.google.com Google C:\Users\*\ folder\

       

       

      # Create shortcuts to a known list URLS
      # File format for CSV is Shortcut Name

      # Change the name between brackets
      $filename = import-csv “C:\Users\b1553\Desktop\Testfiles VBA\Autocreate files in folder from CSV\Test.csv”
      foreach ($i in $filename)
      {
      $ShortcutName = $i.Name
      $Target = $i.Path
      $Location = $i.Location

      # Set the path to the shortcut LNK file
      $FullSPath = $Location +”\”+ $ShortcutName + ‘.url’

      $new_object = New-Object -ComObject WScript.Shell

      $destination = $i.Location
      $source_path = $FullSPath
      $source = $new_object.CreateShortcut($source_path)
      $source.TargetPath = $Target

      $source.Save()

      }

      however, I get the error below when running the script
      Unable to save shortcut “C:\.url”.
      At line:24 char:1

       

      Can someone please help me with this?

      kr
      steve

      • This topic was modified 2 months, 2 weeks ago by Stielo45.
    • #239810
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      The biggest issue is the wildcard path. Try looking up the path with Get-ChildItem:

Viewing 1 reply thread
  • You must be logged in to reply to this topic.