none
Mount windows share in command line via net use with password encrypted. RRS feed

  • Question

  • Hi All,

      I just try to do with this but not importing the password i think?

    Get-Credential | Export-Clixml C:\Users\user\mycredfile1.xml
    $Credential = Import-Clixml C:\Users\user\mycredfile1.xml
    net use X: "\\server\AHS Data" /user:$($Credential.UserName) $($Credential.GetNetworkCredential().Password)

    ================================

    S C:\WINDOWS\system32> Get-Credential | Export-Clixml C:\Users\user\mycredfile1.xml
    $Credential = Import-Clixml C:\Users\user\mycredfile1.xml
    net use X: "\\Server\AHS Data" /user:$($Credential.UserName) $($Credential.GetNetworkCredential().Password)
    cmdlet Get-Credential at command pipeline position 1
    Supply values for the following parameters:
    Method invocation failed because [Deserialized.System.Management.Automation.PSCredential] does not contain a method named 'GetNetworkCredential'.
    At line:3 char:72
    + ... ($Credential.UserName) $($Credential.GetNetworkCredential().Password)
    +                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (GetNetworkCredential:String) [], RuntimeException
        + FullyQualifiedErrorId : MethodNotFound
     
    net : System error 85 has occurred.
    At line:3 char:1
    + net use X: "\\server\AHS Data" /user:$($Credential.UserName)  ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (System error 85 has occurred.:String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError
     
    The local device name is already in use.

    PS C:\WINDOWS\system32> 

    Friday, February 14, 2020 5:03 AM

Answers

  • Hi all,

      Sorry the command working fine i think i already have the X: mapped.

     

    As

    • Marked as answer by AUSSUPPORT Friday, February 14, 2020 10:05 AM
    Friday, February 14, 2020 10:04 AM

All replies

  • You canno5t use a serialized object with methods as all methods have been removed and only the object data is saved.


    \_(ツ)_/

    Friday, February 14, 2020 6:43 AM
  • To rehydrate this object just force the load into a new object of the correct type.:

    $Credential = Import-Clixml C:\Users\user\mycredfile1.xml
    $Credential .GetNetworkCredential().Password


    \_(ツ)_/

    Friday, February 14, 2020 6:48 AM
  • To connect a network drive in PowerShell use "New-PsDrive".


    \_(ツ)_/

    Friday, February 14, 2020 6:49 AM
  • Hi all,

      Sorry the command working fine i think i already have the X: mapped.

     

    As

    • Marked as answer by AUSSUPPORT Friday, February 14, 2020 10:05 AM
    Friday, February 14, 2020 10:04 AM
  • Please mark the answer and not your own last post.  Marking the answer is so that othe5rs can find answers.


    \_(ツ)_/

    Friday, February 14, 2020 10:44 AM