CSV to create URL links - error with saving

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

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

#Emulate CSV Import
$filename = @"
Path,Name,Location
https://www.google.com,Google,C:\Users\*\Favorites
"@ | ConvertFrom-Csv

#$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

    #Find All folders with a wildcard path
    $folders = Get-ChildItem -Path $Location

    foreach ($folder in $folders) {
        $FullSPath = $Location +”\”+ $ShortcutName + ‘.url’

        'Creating shortcut {0} for {1} in location {2}' -f $FullSPath, $Target, $Location
        #$new_object = New-Object -ComObject WScript.Shell

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

        #$source.Save()
    }

}