public/Import-PSCredVault.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function Import-PSCredVault {
    [CmdletBinding()]
    param(
        $VaultPath = (Join-Path $env:UserProfile ".Vault")
     )

    ## Test Vault Folder
    if (!(Test-Path $VaultPath)){
        Write-Error "Path: $VaultPath Doesn't exist. Exiting."
        return
    }

    ## Test Vault for Entries
    $keys = Get-ChildItem $VaultPath
    if (!$keys){
        Write-Warning "Path: $VaultPath exists, but has no entries. Exiting."
        return
    }

    $outstring = ""
    foreach ($key in $keys){

        New-Variable -Name $key.basename -Value (Import-Clixml -path $key.Fullname) -Scope Global -Force
        $outstring = $outstring + " $" + "$($key.basename)"

    }
    Write-Host "Credential have been stored to $outstring" -foregroundcolor green

}# end function