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ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ