Remove-Credential.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<#
.Synopsis
    Removes a PSCredential object associated with the specified name.
 
.Description
    Removes a PSCredential object associated with the specified name and
    persists this information to the disk at $home\AppData\Low\SimplyCredential\.
 
.Parameter Name
    The reference name for the [PSCredential].
#>

function Remove-Credential {
    param([Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)][string]$Name)
    
    if($script:CredList.Keys -contains $name) { 
        $script:CredList.Remove($name)
        $script:CredList | Export-Clixml -Path $script:CredListPath -Force
    }
    else { Write-Warning "The credential '$name' does not exist." }
}

Export-ModuleMember -Function Remove-Credential