powershellvariablesnet-use

Powershell - Net Use credentials not working


i want to automate net use through powershell to bind a lot of share drives.

first i fetch the credentials via Get-Credentials, then i want to use the credentials later.

$cred = Get-Credentials -Message "Enter credentials"
net use K: \\192.168.100.50\E$ /user:$cred.username $cred.password

This throws the error Network password wrong (translated from german)

When i enter it like that: net use K: \\192.168.100.50\E$ /user:Admin Adminpassword

It works? When i replace $cred.password with the plaintext password and only use the username variable it still says Network password wrong

What is conflicting here?


Solution

  • Use powershell to do this, because Get-Credentials store your data as securestring, net use can't work with it.

     $cred = Get-Credentials -Message "Enter credentials"
     New-PSDrive -Name K -PSProvider FileSystem -Root "ComputerName\FilePath" -Persist -Credential $cred