Drive Mapped On Amazon EC2 Instance Startup Disconnected After Logon

Posted by jsn on Server Fault See other posts from Server Fault or by jsn
Published on 2014-08-21T15:15:50Z Indexed on 2014/08/21 16:21 UTC
Read the original article Hit count: 436

I am launching an Amazon EC2 instance (Windows Server 2012), and on startup (though User Data field), it runs this powershell script:

<powershell>
    NET CONFIG SERVER /AUTODISCONNECT:-1

    # clear all prior connections
    net use * /delete /y > C:\delLog.txt 2>&1

    # mount new drive 
    net use R: \\dbHost\share /user:username pass /persistent:yes > C:\useLog.txt 2>&1

    ipconfig /all > C:\ipLog.txt
</powershell>

When it launches and I connect to it through RDP, it shows in explorer "Diconnected Network Drive (R:). If I double click it, error message displays "R:\ is not accesible. Access id denied". Normally, it would ask me for credentials to reconnect.

I need for this drive to be connected through the duration of the instance.

enter image description here

delLog.txt contents:

You have these remote connections:
T:              \\dbHost\share
Continuing will cancel the connections.
The command completed successfully.

useLog.txt contents: The command completed successfully.

ipLog.txt contents as expected.

The net use commands works fine by itself, it connects. Anyone have any idea what could be wrong? There is only one account on these machines - Administrator. It is a samba share to a Linux server on a private network.

© Server Fault or respective owner

Related posts about amazon-ec2

Related posts about amazon-web-services