33 lines
866 B
PowerShell
33 lines
866 B
PowerShell
[CmdletBinding()]
|
|
Param(
|
|
[Parameter()]
|
|
[string]$VaultAPIAddress,
|
|
[Parameter()]
|
|
[string]$VaultToken,
|
|
[Parameter()]
|
|
[string]$VaultPwPolicy,
|
|
[Parameter(Mandatory)]
|
|
[string]$Container,
|
|
[Parameter(Mandatory)]
|
|
[string]$Username
|
|
)
|
|
|
|
$InvokeWebRequestSplat = @{
|
|
Uri = "$($VaultAPIAddress)/sys/policies/password/$($VaultPasswordPolicy)/generate"
|
|
Headers = @{'X-Vault-Token'="$VaultToken"}
|
|
}
|
|
$NewPassword = (Invoke-WebRequest @InvokeWebRequestSplat | ConvertFrom-Json).data.password
|
|
|
|
$InvokeWebRequestSplat = @{
|
|
Uri = "$($VaultAPIAddress)/secret/data/$($Container)"
|
|
Method = 'POST'
|
|
Headers = @{'X-Vault-Token'="$VaultToken"}
|
|
Body = @{
|
|
data = @{
|
|
"password.$($Username)" = $NewPassword
|
|
}
|
|
} | ConvertTo-Json
|
|
}
|
|
Invoke-WebRequest @InvokeWebRequestSplat
|
|
|
|
Return $NewPassword |