Skip to content

Instantly share code, notes, and snippets.

@cmendible
Created January 19, 2018 11:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmendible/c171105b6c407893699e42ebca4fd875 to your computer and use it in GitHub Desktop.
Save cmendible/c171105b6c407893699e42ebca4fd875 to your computer and use it in GitHub Desktop.
A PowerShell module to fetch passwords from Password Manager Pro (PMP).
function Get-PasswordFromPmp {
<#
#.SYNOPSIS
# Gets a password from PMP.
#
#.DESCRIPTION
# Gets a password from PMP.
#
#.PARAMETER pmpServer
# The server name and port where PMP is hosted.
#
#.PARAMETER pmpToken
# The PMP API Token
#
#.PARAMETER pmpRespource
# The resource name for wich the password must be fetched.
#
#.PARAMETER pmpAccount
# The account name for wich the password must be fetched.
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)][String]$pmpServer,
[Parameter(Mandatory = $true)][String]$pmpToken,
[Parameter(Mandatory = $true)][String]$pmpResource,
[Parameter(Mandatory = $true)][String]$pmpAccount
)
$baseUri = "https://$($pmpServer)/restapi/json/v1/resources"
try {
$uri = "$($baseUri)?AUTHTOKEN=$pmpToken"
$resource = ((Invoke-WebRequest -Uri $uri -UseBasicParsing) | ConvertFrom-Json).operation.Details | Where-Object {$_."RESOURCE NAME" -eq $pmpResource}
$resourceId = $resource."RESOURCE ID"
$uri = "$baseUri/$resourceId/accounts?AUTHTOKEN=$pmpToken"
$account = ((Invoke-WebRequest -Uri $uri -UseBasicParsing) | ConvertFrom-Json).operation.Details."ACCOUNT LIST" | Where-Object {$_."ACCOUNT NAME" -eq $pmpAccount}
$passwordId = $account.PASSWDID
$uri = "$baseUri/$resourceId/accounts/$passwordId/password?AUTHTOKEN=$pmpToken"
$operation = ((Invoke-WebRequest -Uri $uri -UseBasicParsing) | ConvertFrom-Json).operation
if ($operation.result.status -eq "Success") {
$password = $operation.Details.Password
$password
}
else {
throw
}
}
catch {
throw "Error trying to get password for account $($pmpAccount) and resource $($pmpResource)"
}
}
Export-ModuleMember Get-PasswordFromPmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment