Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I know how to map network drives through GPOs, but I would like to map a "network location":

enter image description here

I know how to add those on the workstation itself through Windows Explorer:

enter image description here

But I don't know how to add/remove them through GPOs.

share|improve this question
    
I've tried to find an answer for this myself, and came up empty, so let us know if you find something. I've even used procmon to capture file/reg changes. –  Bret Fisher Sep 17 '12 at 22:39
    
@BretFisher: Oh wow, that really puts my hopes down :( I hoped that there is a built-in approach. For this task at hand I really wouldn't want to roll anything from scratch, mapped network drives are actually an option. I'll look into it though, as this seems like a much more elegant approach. If you don't mind, I'd love to have a look at whatever procmon results you'd want to share. My email is in my profile :) –  Oliver Salzburg Sep 17 '12 at 23:38
    
If you are willing to do drive mappings life is good! Use Group Policy Preferences (shown as Preferences in gpo edit mmc) to map drives. Personally I feel the drive mapping concept is legacy but we've got no great alternative for network file share access yet... so map away. Other then only having ~20 letters for mappings, there's no real down side to drive mappings. Preferences let's you map drives on all sorts of if/elseif statements including group membership, any value in AD, or just about any attribute of a machine. What's your reason for wanting network location over drive mappings? –  Bret Fisher Sep 18 '12 at 1:33
    
@BretFisher: Just as you said. It felt legacy and I wanted to see if there are other options. This looked like a much better approach. The concept of drive letters seemed unnecessary, and the drive letter that would fit this network location just perfectly is always already taken by another assignment :D Thanks for your advice. –  Oliver Salzburg Sep 18 '12 at 9:59
    
@BretFisher Turns out it's simply a folder which contents are displayed in that area. You can place anything you want there. Just have a look at C:\Users\username\AppData\Roaming\Microsoft\Windows\Network Shortcuts –  Oliver Salzburg Jun 3 at 14:04

1 Answer 1

up vote 2 down vote accepted

I created the function below to accomplish the very same thing. You can include it as a part of a login script. The usage is as follows:

New-NetworkShortcut -Name 'New Network Shortcut' -Target '\\server\share\path'
function New-NetworkShortcut()
{
    param(
        [Parameter(Mandatory=$true)] [string]$Name,
        [Parameter(Mandatory=$true)] [string]$Target
    )

    $networkshortcut_name = $Name
    $networkshortcut_target = $Target

    $networkshortcuts_path = [Environment]::GetFolderPath('NetworkShortcuts')

    $networkshortcut_path = "$networkshortcuts_path\$networkshortcut_name"
    $desktopini_path = "$networkshortcut_path\desktop.ini"
    $targetlnk_path = "$networkshortcut_path\target.lnk"

    $desktopini_text = "[.ShellClassInfo]`r`nCLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}`r`nFlags=2"

    if( Test-Path -Path $networkshortcut_path -PathType Container )
    {
        Remove-Item -Path $networkshortcut_path -Recurse -Force
    }

    [void](New-Item -Path $networkshortcut_path -ItemType directory)

    Set-ItemProperty -Path $networkshortcut_path -Name Attributes -Value 1

    Out-File -FilePath $desktopini_path -InputObject $desktopini_text -Encoding ascii

    Set-ItemProperty -Path $desktopini_path -Name Attributes -Value 6

    $WshShell = New-Object -com WScript.Shell
    $Shortcut = $WshShell.CreateShortcut($targetlnk_path)
    $Shortcut.TargetPath = $networkshortcut_target
    $Shortcut.Save()
}
share|improve this answer
    
Sorry for the 1year delay ;) This works great and it also made me realize what the underlying concept of these network locations is. I wasn't aware that it is simply a folder into which you can place arbitrary shortcuts. This is pretty awesome. –  Oliver Salzburg Jun 3 at 14:02
    
No problem, I can't believe that was a whole year ago. Glad it works for you! –  charleswj81 Jun 4 at 4:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.