Disconnected Network Drive while connecting to windows using samba

0

We are facing an issue when we are trying to auto-mount a Samba share drive on a Windows EC2 instance. However, when we manually mount it or run the PowerShell script manually, it connects successfully. But when we automate the process using Task Scheduler or EC2 User Data, it doesn't connect and gives a "Disconnected Network Drive" error. I also checked the log of the user data, but it doesn't show any errors. The output file just says "The command completed successfully."

I have tried multiple solutions, such as editing the regedit settings for HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters, and various mounting mechanisms, but none of them seem to work.

Please find the attached screenshot and PowerShell script that I am using for mounting. These PowerShell scripts work fine when I run them manually but do not work when run through automation methods like EC2 User Data and Task Scheduler.

error screen

user-date used in ec2 -

<powershell>
$drive_letter = "Z:"
$username = "username"
$password = "password"
net use $drive_letter "\\sambaserverip\sambashare" /user:$username $password
</powershell>
<persist>true</persist>
<powershell>

# Replace SERVER_IP, SHARE_NAME, USERNAME, and PASSWORD with your Samba server IP, share name, username, and password
$ServerIP = "sambaserverip"
$ShareName = "sambashare"
$Username = "username"
$Password = "password" | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username, $Password

# Mount the Samba share
New-PSDrive -Name "S" -PSProvider FileSystem -Root "\\$ServerIP\$ShareName" -Credential $Credential -Persist
</powershell>
<persist>true</persist>![error screen](/media/postImages/original/IMb5N-omghQN6aiHfm8QeCRQ)

asked a month ago111 views
1 Answer
0

User data only runs once by default when the EC2 is first launched.

You also cant map windows drives for logged off users. If you have a user logging in, you may want to add this to a login script.

profile picture
EXPERT
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions