Docker for windows: Bind mounting an Azure SMB drive fail - windows

I spent days on this issue, can't figure out how it's done?
Mounting the drive letter from Azure file share works fine using
New-PSDrive -Name T -PSProvider FileSystem -Root "\\xxxx.file.core.windows.net\share" -Scope Global -Persist
The drive can be accessed in both PowerShell and in explorer, even after windows reboot.
But when trying to mount that in a container fail to say the path does not exist.
docker run -d --name webserver1 -v T:\:c:\share -p 80:80 microsoft/iis
Error response from daemon: invalid volume specification: 'T:\:c:\share': invalid mount config for type "bind": bind source path does not exist: t:\.
I also tried to add the SMB drive via
New-SmbGlobalMapping -RemotePath "\\xxxx.file.core.windows.net\share" -Credential $credentialObject -LocalPath T: -FullAccess #( "NT AUTHORITY\SYSTEM", "NT AUTHORITY\NetworkService" ) -Persistent $true -RequirePrivacy $true
Then I can bind mount T: but get "access was denied" instead when trying to check c:\share inside the container. What am I doing wrong? Also referring to this: https://github.com/moby/moby/issues/37863
If there is another way to mount the SMB share directly into the container without first mounting it in windows, that would be fine too. I solved it with Linux but doesn't seem to be possible in windows.

Related

Can I name a VeraCrypt volume on Mac OS?

When Veracrypt 1.23 mounts a volume it is name NO NAME.
Is there a way to give these volumes a name?
I am using the console to create my containers
veracrypt -t -c $LOCATION --encryption=AES --hash=SHA-512 --filesystem=FAT --password=$PASSWORD --size=1G --volume-type=Normal --pim=$PIM --keyfiles=
I tried renaming the volume in /Volumes/NO\ NAME but that just removes the volume from the desktop.
And specifying a mount point.
Enter mount directory [default]: /Users/Test
But the volume still mounts as NO NAME
Using diskutil I can rename volumes, as below.
/usr/sbin/diskutil rename "NO NAME" "TEST2"
I am leaving the question open as this is a bit of a hack.

Running an installer from a windows share using ansible

I want to log into a Windows server using a local user, then map a network drive using an Active Directory user and run an installer from it automated with Ansible.
I followed the suggestion from this question to create a PowerShell script and do the mount and the install. I used that script as follows:
Inventory:
[winserver]
windows
[winserver:vars]
ansible_user="local_user"
ansible_password="P#ssw0rd"
ansible_connection="winrm"
ansible_winrm_cert_validation=ignore
win_user="domain\aduser"
win_pass="P#55w0rd"
task yaml:
---
- name: Mount and run a script
script: 'files/maprun.ps1 -map_user {{ win_user }} -map_password {{ win_pass }} -script z:\ascript.ps1'
And the maprun.ps1 script contains the following:
param(
$map_user,
$map_password,
$script
)
$PWord="$map_password"|ConvertTo-SecureString -AsPlainText -Force
$myCreds=New-Object System.Management.Automation.PsCredential($map_user,$PWord)
New-PSDrive -Name "Z" -PSProvider "FileSystem" -Root "\\domain\share" -Credential $myCreds
echo Invoke-Command -ScriptBlock $script
And I get the error:
New-PSDrive: A specified logon session does not exist. It may already have
been terminated
Most hits talk about a double-hop problem, but I am trying to specify different credentials in the remote script, so this isn't a double hop problem. The other answer suggests this ought to be possible. The script works in interactive mode, so it is something to do with being in batch mode. Any ideas how I can get this to work?
I am using Ansible 2.3.1.0 on Red Hat Enterprise Linux. Windows is Windows Server 2012 R2. Scripts were manually typed, sorry for any typos.
I can make a few suggestions.
As you've written it, the script "maprun.ps1" must be saved in the "files" directory of your Linux controller machine. If it is, the "maprun.ps1" script will be copied by Ansible to the remote host, executed and deleted. If "maprun.ps1" is going to call "ascript.ps1" you need to copy "ascript.ps1" over to the remote host before calling "maprun.ps1" and have it's location defined in the context of "maprun.ps1".
You don't need parameter names before the args in your playbook "script:" command.
Args internal to your Ansible playbook need double curly brackets and quotes around them.
As an alternative to connecting to the network drive with the New-PSDrive command you could try the "net use" command as shown below.
So instead of
script: 'files/maprun.ps1 -map_user {{ win_user }} -map_password {{ win_pass }} -script z:\ascript.ps1'
Try
script: files/maprun.ps1 "Z:" "{{ win_user }}" "{{ win_pass }}" "z:\ascript.ps1"
Where maprun.ps1 contains the following...
# connect to a shared resource and run script
param(
[string]$map_server,
[string]$map_user,
[string]$map_password,
[string]$script
)
# connect to the network drive
net use $map_server $map_password /USER:$map_user
Invoke-Item (start powershell ((Split-Path $MyInvocation.InvocationName) + $script))
net use $uncServer /delete

Auto Mount .vhdx on Startup

I have a Surface Pro 4 with a 128 GB micro SD card to expand storage space. Sadly, Windows sees the SD card as a removable device and not a permanent hard drive, I did find a guide on how to work around this(See link below), however I am having trouble automatically mounting a .vhdx on startup. I created a .vhdx on the SD card, as the guide said, and want the .vhdx to mount on startup using task scheduler.
I have tried to use powershell and a .ps1 file to mount the .vhdx, however, this has not worked.
Mount-DiskImage A:\Fix.vhdx
Screenshot: Disk Management
I am following this guide: Configure Surface to use MicroSD as Primary Storage
According to your screenshot, Fix.vhdx is on I:.
Mount-DiskImage I:\Fix.vhdx
Note that, depending on your OS (Windows 8), you must be an Administrator to mount the disk. If you have the Hyper-V Cmdlets available, prefer ´Mount-VHD´.
I found a solution better than using powershell and task scheduler. VHD Attach is a utility made by Medo64 and that automatically mounts VHDs on startup.
Here is a simple way to mount a .vhd or .vhdx and assign it a drive letter utilizing PowerShell:
$VolumesVHDX = Mount-VHD -Path C:\mynewdisk.vhdx -PassThru | Get-Disk | Get-Partition | Get-Volume | Select-Object DriveLetter
Set-Partition -DriveLetter $VolumesVHDX.DriveLetter -NewDriveLetter L -Confirm:$false -ErrorAction SilentlyContinue
Save it as a PowerShell script, then create a Scheduled Task to run at system startup.
Command > PowerShell.exe
Arguments > "C:\Mount_VHDX_Drives.ps1"

Accessing SMB share from Windows when using Powershell

I'm trying to build a custom VeeamZip backup script using PowerShell from a Windows 7 box. The box doesn't have the space requirements to hold the actual data itself, it's just the catalyst to manage the VeeamZip files.
I've been hunting around and found a solution here on SO to work around the fact that the PS-Drive command doesn't function using the -Credentials flag in PowerShell 2.0 using this snippet:
$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("u:", "\\share\point", $false, "user", "pass")
I can verify this is properly mounting the share and is searchable using Powershell, but when using the VeeamZip Powershell commands, the path U:\ isn't available.
I tried then using the net use command in Powershell which also mounted the volume, but even with /persistent:yes it won't show in Explorer and the backups fail.
What can I do? There has to be option to get this to work. I'm a Linux guy so I'm not powershell wiz.
EDIT: I've now updated to Powershell 3.0 and I still can't get it work...
I'm trying the following snippet, but only Powershell has access the new drive:
$credential = Get-Credential
New-PSDrive -Name V -PSProvider FileSystem -Root \\server\share -Credential $credential -Persist
EDIT: The New-PSDrive function now works to mount the volume in Explorer and can be browsed as expected as long as I don't launch PowerShell as administrator. The dilemma is now that I can't use the VeeamZip tool because it requires Admin to function. Ideas welcome.

Powershell drive map with authentication?

I am trying to make a script in powershell (if you have suggestions for another tool to make this with please advise) that would map network drives for userA to map their own drives temporarily while userB is still logged in.
I tried to use both the New-PSDrive method, as well as the MapNetworkDrive method.
They both throw this error:
"Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again"
After I saw this, I tried disconnecting all drives associated with the server before connecting the desired share via:
net use * /d /y
net use \\server\ipc$
net use \\server\ipc$ /d /y
(thanks #jessehouwing !)
The same error still occurs.
If you want to check my connection code I have it below:
$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive($drLetter, $share, $false, $user, $pass)
and
New-PSDrive -Name $drLetter -PSProvider FileSystem -Root $share -Credential $user -Persist
You are getting that error because you are not allowed to have multiple connection to the same resource with different credentials. I am going to Assume you don't just have a temporary connection to this resource defined by server.
What I always to in situations like this is use the IP address of the host. so...
net use \\10.10.10.10\ipc$
I am going to try and find the articles that discuss what is occurring here but in short this will allow the separate connections.

Resources