Functions/Authentication/PSCredential/Rename-Credential.ps1
function Rename-Credential { [CmdletBinding()] Param ( # Incoming Credential [Parameter(Mandatory=$true,ValueFromPipeline=$true)] [pscredential] $Credential, [Parameter(Mandatory=$false,ParameterSetName='NoDomain')] [switch] $NoDomain, [Parameter(Mandatory=$false,ParameterSetName='Overwrite')] [string] $NewName ) Process { if ($NoDomain) { $UserName = if($credential.username -like "*\*"){($credential.username -split '\\')[1]}else{$Credential.username} $ReCred = New-Object pscredential ($UserName,$credential.password) } if ($NewName) { $UserName = $NewName $ReCred = New-Object pscredential ($NewName,$Credential.password) } if ($ReCred){$ReCred} } } |