Add a Network Location via Script


  • I am looking to script some office standard "Network Locations" which happen to also be DFS shares. We have some software (AutoCAD & Revit) that really doesn't like accessing DFS shares directly, but will work happily with a Network Location that points at a DFS share. But I can find no automated way to roll these out, just going machine to machine manually right clicking Computer in Windows Explorer and choosing Add a Network Location. Five Network Locations, multiple clicks each, and 30 users, makes this a lot of work. Hopefully there is a PowerShell or WindowsScriptHost alternative.

    All machines are Windows 7 x64 if that makes a difference.




    Wednesday, March 31, 2010 1:21 AM


  • Hi Gordon,

    I've put together a PowerShell function which will create a Network Location based on a name and a target path. It shouldn't be too hard to take this and run it remotely on all machines.

    Hope it helps,

    function Add-NetworkLocation
        # Get the basepath for network locations
        $shellApplication = New-Object -ComObject Shell.Application
        $nethoodPath = $shellApplication.Namespace(0x13).Self.Path
        # Only create if the local path doesn't already exist & remote path exists
        if ((Test-Path $nethoodPath) -and !(Test-Path "$nethoodPath\$name") -and (Test-Path $targetPath))
            # Create the folder
            $newLinkFolder = New-Item -Name $name -Path $nethoodPath -type directory
            # Create the ini file
            $desktopIniContent = @"
            $desktopIniContent | Out-File -FilePath "$nethoodPath\$name\Desktop.ini"
            # Create the shortcut file
            $shortcut = (New-Object -ComObject WScript.Shell).Createshortcut("$nethoodPath\$name\target.lnk")
            $shortcut.TargetPath = $targetPath
            $shortcut.IconLocation = "%SystemRoot%\system32\SHELL32.DLL, 85"
            $shortcut.Description = $targetPath
            $shortcut.WorkingDirectory = $targetPath
            # Set attributes on the files & folders
            Set-ItemProperty "$nethoodPath\$name\Desktop.ini" -Name Attributes -Value ([IO.FileAttributes]::System -bxor [IO.FileAttributes]::Hidden)
            Set-ItemProperty "$nethoodPath\$name" -Name Attributes -Value ([IO.FileAttributes]::ReadOnly)


    Wednesday, April 14, 2010 11:23 AM