• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Using PowerShell to Create Shortcuts From List of Values

shawn130c

Senior member
I’m working on a way to use powershell to create a shortcut to a network folder using values from two different lists. I have the code to create the shortcut but now I need it to reference values from the list to make a shortcut. My googlefu has failed me in finding an easy way to accomplish this.

Here is the code for the shortcut, I found through google:

Code:
$strDesktopFolder = "C:\test"
$objShell = New-Object -com "Wscript.Shell"
$objShortcut = $objShell.CreateShortcut($strDesktopFolder + "\PleaseSaveMe.lnk")
$objShortcut.TargetPath = "\\myserver\folder"
$objShortcut.Save()

Here is the code again for the values I need to change:

Code:
$strDesktopFolder = "C:\test"
$objShell = New-Object -com "Wscript.Shell"
$objShortcut = $objShell.CreateShortcut($strDesktopFolder + "\X.lnk")
$objShortcut.TargetPath = "Y"
$objShortcut.Save()

X=First Row of List 1
Y=First row of List 2

Here is sample of the data I am working with:
List 1:
1. Client1
2. Client2
List 2:
1. Client1 Network Folder
2. Client2 Network Folder

I can make the lists how ever they need to be, but I just need a way to easily generate a shortcut from this list. Research shows powershell can import a CSV, I am just not sure how to reference/create the "loop" for it to make all shortcuts at once. Any help is appreciated.
 
After some more research, I found an article that had an example of import-csv and foreach. This seems to have gotten my code working the way I want it:

Code:
$csv = Import-Csv C:\test\importdata\testdata.csv -Header @("name","location")
$strSaveFolder = "C:\test\shortcuts\"
foreach ($line in $csv) {
$objShell = New-Object -com "Wscript.Shell"
$objShortcut = $objShell.CreateShortcut($strSavefolder+"$($line.name).lnk")
$objShortcut.TargetPath = $($line.location)
$objShortcut.Save()
}

Note: I am using one CSV with two columns (Name, Location)

I am still doing some additional testing, but I would still be interested in better/cleaner ways to do this.
 
Back
Top