Created
January 19, 2018 11:31
-
-
Save cmendible/c171105b6c407893699e42ebca4fd875 to your computer and use it in GitHub Desktop.
A PowerShell module to fetch passwords from Password Manager Pro (PMP).
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 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