Functions/Authentication/PSCredential/MCM/Remove-MCMCredential.ps1
<#
.DESCRIPTION This script removes secured credentials in the Microsoft Credential Manager The target, username, and hint bindings are maintained in the MCI Memspace (via Import-MCMCredentialInfo) #> function Remove-MCMCredential { [CmdletBinding()] Param() DynamicParam { # Get MCM Credential Info $MCMInfo = Import-MCMCredentialInfo # Dynamic Parameter for MCI Targets $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary $ParameterName = "Target" $RunTimeParameter = New-DynamicParameter -ParamName $ParameterName -ValueType string -DataSet $MCMInfo.Target -Mandatory:$true $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter) return $RuntimeParameterDictionary } Begin { # Burn in parameter variables from Runtime Parameter Dictionary foreach ($key in $RuntimeParameterDictionary.keys){New-Variable -Name $key -Value $RuntimeParameterDictionary.$key.value} } Process { # Check for Existing Credential in the Microsoft Credential Manager $MCMCredential = Get-MCMCredential -Target $Target if ($MCMCredential) { # Remove the existing MCM Credential $REM = Remove-StoredCredential -Target $Target Write-Host "Removed credential (Target: $Target Username: $($MCMCredential.username)) in $ENV:Username's Vault" -ForegroundColor Yellow } else { # If you didn't find the requested credential Write-Host "Could not find a credential with Target: $Target in $ENV:UserName's Vault" -ForegroundColor Green } } } |