Sometimes cmdlets are asking for plain-text passwords instead of Secure Strings. And the New-SmbMapping cmdlet (developed by Microsoft! Huh!) is one of them.
New-SmbMapping -LocalPath Z: -RemotePath \\RemoteServerName\ShareName -UserName MyUserName -Password 'MyClearPassword'
However, because you are a serious person, you won’t type the password in clear. This would not only expose your password to someone looking over your shoulder, but also to anybody having access to the computer’s log files…
So what can you do?
Fortunately, with the PSCredential object you can retrieve both a Secure String with the Password
property but also the unencrypted password with the GetNetworkCredential
method.
Here is an example on how to retrieve the plain-text password applied to the New-SmbMapping cmdlet:
$Credential = Get-Credential New-SmbMapping -LocalPath Z: -RemotePath \\RemoteServerName\ShareName -UserName $Credential.UserName -Password $Credential.GetNetworkCredential().Password