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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠