2017-09-21 13:32:15 +02:00
|
|
|
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.
|
|
|
|
|
2019-04-29 16:05:43 +02:00
|
|
|
.EXAMPLE
|
|
|
|
Test-CredentialStore -eq $true
|
2017-09-21 13:32:15 +02:00
|
|
|
#>
|
2022-06-28 08:56:33 +02:00
|
|
|
|
|
|
|
[CmdletBinding(DefaultParameterSetName = 'Private')]
|
|
|
|
[OutputType([bool])]
|
|
|
|
param (
|
|
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
2019-01-16 12:55:29 +01:00
|
|
|
[string]$Path,
|
2017-09-21 13:32:15 +02:00
|
|
|
|
2022-06-28 08:56:33 +02:00
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
2017-09-21 13:32:15 +02:00
|
|
|
[switch]$Shared
|
|
|
|
)
|
|
|
|
|
2022-06-28 08:56:33 +02:00
|
|
|
begin {}
|
2017-09-21 13:32:15 +02:00
|
|
|
|
2019-01-16 12:55:29 +01:00
|
|
|
process {
|
|
|
|
# Set the CredentialStore for private, shared or custom mode.
|
|
|
|
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
2022-06-28 08:56:33 +02:00
|
|
|
if ($PSCmdlet.ParameterSetName -eq 'Private') {
|
2019-01-16 12:55:29 +01:00
|
|
|
$Path = Get-DefaultCredentialStorePath
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
2022-06-28 08:56:33 +02:00
|
|
|
elseif ($PSCmdlet.ParameterSetName -eq 'Shared') {
|
2019-01-16 12:55:29 +01:00
|
|
|
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
|
|
|
$Path = Get-DefaultCredentialStorePath -Shared
|
|
|
|
}
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
2019-01-16 12:55:29 +01:00
|
|
|
Write-Verbose -Message ("Path is: {0}" -f $Path)
|
2017-09-21 13:32:15 +02:00
|
|
|
|
2019-01-16 12:55:29 +01:00
|
|
|
if (Test-Path $Path) {
|
2022-06-28 08:56:33 +02:00
|
|
|
Write-Verbose 'CredentialStore in given path found.'
|
|
|
|
Write-Output $true
|
2019-01-16 12:55:29 +01:00
|
|
|
}
|
|
|
|
else {
|
2022-06-28 08:56:33 +02:00
|
|
|
Write-Verbose 'The given CredentialStore does not exist!'
|
|
|
|
Write-Output $false
|
2019-01-16 12:55:29 +01:00
|
|
|
}
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
2019-01-16 12:55:29 +01:00
|
|
|
|
2022-06-28 08:56:33 +02:00
|
|
|
end {}
|
2019-01-16 12:55:29 +01:00
|
|
|
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|