Skip to content

Labeling Symlinks in Windows

Published: at 07:03 PM

I’ve wanted to programmaticly lable symlinks since a decade. Found some time on how to get that done.

COM Interface Method

$a = New-Object -ComObject shell.application
$a.NameSpace("Z:").self.name = "dump"

PowerShell Native Method

New-Item -ItemType SymbolicLink -Path "Z:" -Target "C:\dump"
Set-ItemProperty -Path "Z:" -Name "Label" -Value "dump"

Error Handling

try {
    $a = New-Object -ComObject shell.application
    $a.NameSpace("Z:").self.name = "dump"
} catch {
    Write-Error "Failed to set symlink label: $_"
}
  1. Verification
# Verify the label
$a.NameSpace("Z:").self.name

Previous Post
C#'s Hidden Gems and Modern Features
Next Post
Configuring Public Folder Access with .htaccess