SMB share mappings created with New-SmbGlobalMapping for docker containers not restored after reboot on windows server 1803 SMB share mappings created with New-SmbGlobalMapping for docker containers not restored after reboot on windows server 1803 powershell powershell

SMB share mappings created with New-SmbGlobalMapping for docker containers not restored after reboot on windows server 1803


For those stumbling on this, New-SmbGlobalMapping has a Persistent flag that needs to be set to $true, i.e.

New-SmbGlobalMapping -Persistent $true -RemotePath \\contosofileserver\share1 -Credential $creds -LocalPath G:


I also use this cmdlet with Windows Server 1803 and Docker. To solve this problem I do the following:

Create this PS1 script in C:\data\smbshare.ps1

$secpasswd = ConvertTo-SecureString 'password' -AsPlainText -Force;$creds = New-Object System.Management.Automation.PSCredential ("domain\user", $secpasswd);New-SmbGlobalMapping -RemotePath 'RemotePath' -Credential $creds -LocalPath X:;

Now, create a Scheduled Task that start with the server StartUP. I do this with this cmdlet:

$Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-file C:\data\smbshare.ps1" -WorkingDirectory "C:\data";$Trigger = New-ScheduledTaskTrigger -AtStartup;$Settings = New-ScheduledTaskSettingsSet -DontStopOnIdleEnd -RestartInterval (New-TimeSpan -Minutes 1) -RestartCount 10 -StartWhenAvailable;$Settings.ExecutionTimeLimit = "PT0S";$SecurePassword = ConvertTo-SecureString 'password' -AsPlainText -Force;$UserName = "domain\user";$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword;$Password = $Credentials.GetNetworkCredential().Password;$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings;$Task | Register-ScheduledTask -TaskName 'SMBGlobalShare' -User "domain\user" -Password $Password;