From 35616fa56432de1c91df010f6ae1ae18a713bcc1 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 3 Apr 2019 11:41:13 +0200 Subject: [PATCH] add error handling for credential store path --- src/Store/New-CredentialStore.ps1 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Store/New-CredentialStore.ps1 b/src/Store/New-CredentialStore.ps1 index bcd7864..ae25b99 100644 --- a/src/Store/New-CredentialStore.ps1 +++ b/src/Store/New-CredentialStore.ps1 @@ -59,7 +59,20 @@ function New-CredentialStore { [Parameter(Mandatory = $false, ParameterSetName = "Shared")] [ValidateNotNullOrEmpty()] - [string]$Path, + [ValidateScript( + { + if ($_.Attributes -contains 'Directory') { + throw 'Please provide a full path containing the credential store file name with the .json extension!' + } + elseif ( ($null -eq $_.Extension) -or ($_.Extension -ne '*.json')) { + throw 'Your provided path does not conain the required file extension .json !' + } + else { + $true + } + } + )] + [System.IO.FileInfo]$Path, [Parameter(Mandatory = $false, ParameterSetName = "Private")] [Parameter(Mandatory = $false, ParameterSetName = "Shared")]