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)

posta 2 mesi fa119 visualizzazioni
1 Risposta
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
ESPERTO
con risposta 2 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande