src/Initialize-CsStore.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
31
32
33
<#
.SYNOPSIS
    Creates a new CredentialStore
.DESCRIPTION
    The Initialize-CsStore cmdlet create a new CredentialStore file.
.PARAMETER FilePath
    Specifies the path for the new CredentialStore file.
.Example
    Initialize-CsStore -FilePath CredentialStore.json
    This command will create a new keysore file called CredentialStore.json.
.LINK
    https://github.com/fodonnel/CredentialStore
#>

function Initialize-CsStore {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true, Position = 0)]
        [Alias("File")]
        [string] $FilePath
    )

    if (Test-Path $FilePath) {
        throw "File already exists, cannot overwrite"
    }

    ConvertTo-Json @{
        UserName = $(whoami)
        ComputerName = $(hostname)
        CreatedDate = (Get-Date).ToString()
        FileFormatVersion = "1.0"
        Credentials = @()
    } | Out-File -FilePath $FilePath
}