Skip to content

Instantly share code, notes, and snippets.

@Robert-LTH
Created December 19, 2018 09:19
Show Gist options
  • Save Robert-LTH/108fcb81d92ab50570b3a1037662f3aa to your computer and use it in GitHub Desktop.
Save Robert-LTH/108fcb81d92ab50570b3a1037662f3aa to your computer and use it in GitHub Desktop.
function New-ExplorerContextMenuEntry {
param(
$Identifier,
$icon,
$MenuText,
$command,
$Class
)
$OldLocation = Get-Location
try {
$Path = 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\{0}' -f $Class
Set-Location -LiteralPath $Path -ErrorAction Stop
} catch {
Write-Host "Failed to enter known key: $_"
return
}
New-Item -ItemType Container -Name 'shell' | Out-Null
New-Item -ItemType Container -Name $Identifier -Path '.\shell' | Out-Null
New-Item -ItemType Container -Name 'command' -Path ".\shell\$Identifier" | Out-Null
New-ItemProperty -Name 'icon' -Value $Icon -PropertyType 'ExpandString' -Path ".\shell\$Identifier" | Out-Null
New-ItemProperty -Name '(Default)' -Value $MenuText -PropertyType 'ExpandString' -Path ".\shell\$Identifier" | Out-Null
New-ItemProperty -Name '(Default)' -Value $command -PropertyType 'ExpandString' -Path ".\shell\$Identifier\command" | Out-Null
Set-Location $OldLocation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment