Created
September 15, 2015 03:50
-
-
Save aetos382/c808345a9d112b2549dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ConvertTo-Dictionary { | |
param( | |
[Parameter(Mandatory, Position = 0, ValueFromPipeline)] | |
[PSObject[]] $InputObject = @()) | |
@($InputObject) | % { | |
$result = @{} | |
$obj = $_ | |
$props = $obj | Get-Member -MemberType Properties | |
$props | % { | |
$name = $_.Name | |
$result[$name] = $obj.$name | |
} | |
return $result | |
} | |
} | |
function Test-FileSystemPath { | |
param( | |
[Parameter(Mandatory, Position = 0)] | |
[string] $Path) | |
[System.Management.Automation.ProviderInfo] $provider = $null | |
$ExecutionContext.SessionState.Path.GetResolvedProviderPathFromPSPath($Path, [ref] $provider) > $null | |
$r = $provider.Name -eq 'FileSystem' | |
return $r | |
} | |
function Get-ExtensionName { | |
param( | |
[Parameter(Mandatory, Position = 0)] | |
[string] $Path) | |
if ($ExecutionContext.SessionState.InvokeProvider.Item.IsContainer($Path)) { | |
$Path = Join-Path $Path 'extension.vsixmanifest' | |
} | |
$manifest = [xml] (Get-Content $Path) | |
if ($manifest.PackageManifest) { | |
$name = $manifest.PackageManifest.Metadata.DisplayName | |
} | |
elseif ($manifest.Vsix) { | |
$name = $manifest.Vsix.Identifier.Name | |
} | |
else { | |
throw "Unknown Manifest Schema : $Path" | |
} | |
if ($name.'#text') { | |
$name = $name.'#text' | |
} | |
return $name | |
} | |
function Get-VSExtension { | |
param( | |
[string] $VSVersion = '14.0') | |
$props = Get-ItemProperty "HKCU:\Software\Microsoft\VisualStudio\$VSVersion\ExtensionManager\EnabledExtensions" | |
$props = $props | ConvertTo-Dictionary | |
$props.Keys | % { | |
$key = $_ | |
$value = $props[$key] | |
$path = $value | |
if (!(Test-Path $path)) { | |
return | |
} | |
if (!(Test-FileSystemPath $path)) { | |
return | |
} | |
$name = Get-ExtensionName $path | |
[PSCustomObject] @{ | |
Name = $name | |
Path = $path | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment