Skip to content

Instantly share code, notes, and snippets.

@jasonchester
Last active February 26, 2019 16:27
Show Gist options
  • Save jasonchester/8d659390afa493b3db89f7273610c22c to your computer and use it in GitHub Desktop.
Save jasonchester/8d659390afa493b3db89f7273610c22c to your computer and use it in GitHub Desktop.
$config = ([XML](Get-Content -Path "$env:APPDATA\NuGet\nuget.config"))
Add-Type -AssemblyName 'System.Security'
function Decrypt-NugetPassword ([string] $encryptedString)
{
$entropyBytes = [System.Text.Encoding]::UTF8.GetBytes('NuGet')
$encryptedBytes = [Convert]::FromBase64String($encryptedString)
$passwordBytes = [System.Security.Cryptography.ProtectedData]::Unprotect($encryptedBytes, $entropyBytes, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)
return [System.Text.Encoding]::UTF8.GetString($passwordBytes)
}
$config.configuration.packageSourceCredentials.ChildNodes |
ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
Username = ($_.add | Where-Object 'key' -eq 'Username').value
Password = Decrypt-NugetPassword(($_.add | Where-Object 'key' -eq 'Password').value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment