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)

已提问 2 个月前119 查看次数
1 回答
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
专家
已回答 2 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则