I had a friend ask help in creating a shortcut link in Windows 7 under My Computer Network Locations.  This is the place where mapped drives usually show up.  I will not go into why a mapped drive would not work.

I knew that powershell could do this and quickly found lots of information on creating shortcuts on the Desktop, startup, My Documents, and other locations but nothing on creating under My Computer.  PowerShell has many Environment variables available to use.  There are Special folder variables that hold the path to well known locations like My Computer, My Documents, ApplicationData, etc.  To see a complete list use this command:

[System.Environment+SpecialFolder] | Get-Member -static -memberType Property

I then proceeded to test a few scripts to create the shortcut under My Computer location and it was not working.  I could create the shortcut anywhere else except under My Computer > Network Locations.  When you run the following command:

[System.Environment+SpecialFolder] |
Get-Member -static -memberType Property |
ForEach-Object { "{0,-25}= {1}" -f $_.name, `
[Environment]::GetFolderPath($_.Name) }

you will see the physical path to all the locations available under System.Environment+SpecialFolder and one thing I noticed is that MyComputer had a blank for location.  So where was the .lnk file stored?  I manually created a shortcut and searched the C:\ and from there it was easy.  It turns out the shortcut is stored under [Environment]::GetFolderPath("ApplicationData")\Microsoft\Windows\Network Shortcuts\.  Once armed with that information I created the following script:

[Environment]::GetFolderPath("ApplicationData")
$path = [Environment]::GetFolderPath("ApplicationData") + "\Microsoft\Windows\Network Shortcuts\ShortcutName.lnk"
$comobject = New-Object -comObject WScript.Shell
$link = $comobject.CreateShortcut($path)
#targetpath can be UNC path or physical path to .exe
$link.targetpath = "\\server\share"
$link.IconLocation = "%SystemRoot%\system32\imageres.dll,137"
$link.Save()

One thing to note is that [Environment]::GetFolderPath("ApplicationData") will not work for everyone.  In some cases this will get you to wrong path and at that point you can just build the path using other environment variables like $env.username & $env.systemdrive.

The IconLocation needs two things.  The path to a dll or exe and the number of which image to display.  In this case I'm using imageres.dll which has a lot of icons to choose from.

Hope this helps someone.  I did some googling and never found an answer.