PSCredentialStore/src/Store/Test-CredentialStore.ps1

59 lines
1.7 KiB
PowerShell
Raw Normal View History

function Test-CredentialStore {
<#
.SYNOPSIS
Returns the credential store state.
.DESCRIPTION
Use this script to test your credential store. For now it only checks if
the file exists.
.PARAMETER Path
Define a custom path to a shared CredentialStore.
.PARAMETER Shared
Switch to shared mode with this param. This enforces the command to work with a shared CredentialStore which
can be decrypted across systems.
.EXAMPLE
Test-CredentialStore -eq $true
#>
2022-06-28 08:24:33 +02:00
2022-06-13 09:55:31 +02:00
[CmdletBinding(DefaultParameterSetName = 'Private')]
2022-06-14 14:39:55 +02:00
[OutputType([bool])]
2022-06-13 09:55:31 +02:00
param (
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
[string]$Path,
2022-06-13 09:55:31 +02:00
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
[switch]$Shared
)
2022-06-13 09:55:31 +02:00
begin {}
process {
# Set the CredentialStore for private, shared or custom mode.
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
2022-06-13 09:55:31 +02:00
if ($PSCmdlet.ParameterSetName -eq 'Private') {
$Path = Get-DefaultCredentialStorePath
}
2022-06-13 09:55:31 +02:00
elseif ($PSCmdlet.ParameterSetName -eq 'Shared') {
if (!($PSBoundParameters.ContainsKey('Path'))) {
$Path = Get-DefaultCredentialStorePath -Shared
}
}
Write-Verbose -Message ("Path is: {0}" -f $Path)
if (Test-Path $Path) {
2022-06-13 09:55:31 +02:00
Write-Verbose 'CredentialStore in given path found.'
Write-Output $true
}
else {
2022-06-13 09:55:31 +02:00
Write-Verbose 'The given CredentialStore does not exist!'
Write-Output $false
}
}
2022-06-13 09:55:31 +02:00
end {}
}