Event details
Join us for a special Ask Microsoft Anything (AMA) live stream on Windows manageability! Our engineering and product teams will be answering all your questions around windows enrollment, updates, con...
Heather_Poulsen
Updated Dec 27, 2024
timmahw
Apr 27, 2022Copper Contributor
"How do I map drives now??" is an extremely common question with several community-authored hacky solutions that seek to mirror GP behavior. Is the continued lack of native drive map policies a technical challenge, strategic decision, neither?
soooner
Apr 27, 2022Copper Contributor
We use proactive remediations.
- Steven-HApr 27, 2022Brass Contributor
I use Win32 app in user context to deploy a Network Location (not a letter-mapped drive). I created the solution developed before pro-active remediations existed as a feature. I would love to have this built into a configuration template of some kind or shortcut/drive/network location deployment type.
<# .SYNOPSIS Creates a proper Network Location .DESCRIPTION This script will create/re-create a 'true' network location as opposed to a shortcut sitting within the Network Location's directory .EXAMPLE PS C:\> <name_of_script>.ps1 -Name MyShortcut -Path \\server\folder -IconIndex 4 Creates a Network Location with the name of 'MyShortcut' pointing to \\server\folder with an optional change to the icon .PARAMETER Name String that will become the network location's display name. Mandatory. .PARAMETER Path String containing the UNC or HTTP path to the resource. Mandatory. .PARAMETER IconIndex Optional integer that specifies which Shell32.dll icon will be used for the shortcut. Default value is 4 (Folder Icon) .OUTPUTS A network shortcut .NOTES Will pave over a shortcut with the same name by deleting it Execute in the context of the user who needs the shortcut. #> [CmdletBinding()] param ( # Display Name for Network Location [Parameter(Mandatory = $true)] [ValidateNotNullorEmpty()] [string] $Name, # Network Location Path [Parameter(Mandatory = $true)] [ValidateNotNullorEmpty()] [string] $Path, # Shell32 Icon Index [Parameter(Mandatory = $false)] [ValidateRange(0, 328)] [int] $IconIndex = 4 ) # Paths $NetworkShortcutsRoot = "$env:APPDATA\Microsoft\Windows\Network Shortcuts" $NetworkShortcutPath = (Join-Path -Path $NetworkShortcutsRoot -ChildPath $Name) # desktop.ini content $IniFileContent = '[.ShellClassInfo] CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D} Flags=2 ' # Delete existing shortcut to allow 'updating' if (Test-Path -Path $NetworkShortcutPath) { Remove-Item -Path $NetworkShortcutPath -Recurse } # Create folder and set required read-only attribute New-Item -Path $NetworkShortcutPath -ItemType Directory (Get-Item -Path $NetworkShortcutPath).Attributes = 'ReadOnly', 'Directory' # Create target.lnk $WScriptShell = New-Object -ComObject WScript.Shell $Shortcut = $WScriptShell.CreateShortcut("$NetworkShortcutPath\target.lnk") $Shortcut.TargetPath = $Path $Shortcut.IconLocation = "$env:windir\System32\SHELL32.dll,$IconIndex" $Shortcut.Save() # Create desktop.ini New-Item -Path $NetworkShortcutPath -Name 'desktop.ini' -ItemType File -Value $IniFileContent