retrive password ($credential) using powershell command doest work in all server ? RRS feed

  • Question

  • Hi,

    below command for getting the password via powershell works for 1 server but throws and error for other server machine ?

    Commnand - $credential.GetNetworkCredential().password

    Error -

    You cannot call a method on a null-valued expression.
    At line:1 char:33
    + $credential.GetNetworkCredential <<<< ().password
        + CategoryInfo          : InvalidOperation: (GetNetworkCredential:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull


    • Moved by Bill_Stewart Sunday, November 2, 2014 8:16 PM Unanswerable drive-by question
    Tuesday, September 16, 2014 3:06 AM

All replies

  • There is no such command.  It is an Object that is obtained by calking Get-Credential.

    PS C:\scripts> $cred=Get-Credential domain\somename
    PS C:\scripts> $cred
    UserName                                                                                                       Password
    --------                                                                                                       --------
    domain\somename                                                                            System.Security.SecureString
    PS C:\scripts> $nw=$cred.GetNetworkCredential()
    PS C:\scripts> $nw
    UserName                                           Domain
    --------                                           ------
    somename                                           domain
    PS C:\scripts>

    This construct:


    Will only work on PowerShell V3 or later.

    Your $credential object is null.  That is why you are getting an error.


    Tuesday, September 16, 2014 3:27 AM