Functions/FoldersFiles/Unlock-PVFile.ps1

Function Unlock-PVFile {

    <#
    .SYNOPSIS
    Unlocks a file or password, enabling other Users to retrieve it.

    .DESCRIPTION
    Exposes the PACLI Function: "UNLOCKFILE"

    .PARAMETER vault
    The defined Vault name

    .PARAMETER user
    The Username of the User carrying out the task.

    .PARAMETER safe
    The name of the Safe in which the file is stored.

    .PARAMETER folder
    The name of the folder in which the file is stored.

    .PARAMETER file
    The name of the file or password to unlock.

    .PARAMETER sessionID
    The ID number of the session. Use this parameter when working
    with multiple scripts simultaneously. The default is ‘0’.

    .EXAMPLE
    Unlock-PVFile -vault lab -user administrator -safe Prod_Servers -folder root -file Adminpass

    Unlocks file Adminpass in safe Prod_Servers

    .NOTES
    AUTHOR: Pete Maan

    #>


    [CmdLetBinding()]
    param(

        [Parameter(
            Mandatory = $True,
            ValueFromPipelineByPropertyName = $True)]
        [string]$vault,

        [Parameter(
            Mandatory = $True,
            ValueFromPipelineByPropertyName = $True)]
        [string]$user,

        [Parameter(
            Mandatory = $True,
            ValueFromPipelineByPropertyName = $True)]
        [Alias("Safename")]
        [string]$safe,

        [Parameter(
            Mandatory = $True,
            ValueFromPipelineByPropertyName = $True)]
        [string]$folder,

        [Parameter(
            Mandatory = $True,
            ValueFromPipelineByPropertyName = $True)]
        [Alias("Filename")]
        [string]$file,

        [Parameter(
            Mandatory = $False,
            ValueFromPipelineByPropertyName = $True)]
        [int]$sessionID
    )

    PROCESS {

        $Return = Invoke-PACLICommand $Script:PV.ClientPath UNLOCKFILE $($PSBoundParameters.getEnumerator() |
                ConvertTo-ParameterString)

        if($Return.ExitCode -eq 0) {

            Write-Verbose "$file Unlocked"

            [PSCustomObject] @{

                "vault"     = $vault
                "user"      = $user
                "sessionID" = $sessionID
                "Safename"  = $safe
                "Folder"    = $folder
                "Filename"  = $file

            } | Add-ObjectDetail -TypeName pacli.PoShPACLI

        }

    }

}