0

I am using Powershell and trying to copy a file to an Azure File Share. The Script I am creating creates a Sql Server backup and copies the backup file to the Azure File Share. I want to do this from a central VM because I want to run the script on multiple machines without having to log into each of them.

Connectivity looks something like this:

DeployServer-> SqlServer1 -> Azure File Share

On SqlServer1 I have created a mapped drive using the script provided by the AZ Portal. I have executed this script with Administrator privileges. I can connect and browse to the share from SqlServer1. I can display the contents of the File Share in Explorer and Powershell while RDP’d in to SqlServer1.

This is the script (connectivity details obfuscated) I ran to map this drive. This was provided by AZ Portal:

$connectTestResult = Test-NetConnection -ComputerName sumcomputername0.file.core.windows.net -Port 445 
if ($connectTestResult.TcpTestSucceeded) { 
  # Save the password so the drive will persist on reboot
  cmd.exe /C "cmdkey /add:`"sumcomputername0.file.core.windows.net`" /user:`"Azure\sumteststorage0`" /pass:`"OMITTED FOR SECURITY`""
  # Mount the drive
  New-PSDrive -Name Z -PSProvider FileSystem -Root "\\sumcomputername0.file.core.windows.net\ctestfileshare" -Persist 
}
else {
  Write-Error -Message "Unable to reach the Azure storage account via port 445. Check to make
  sure your organization or ISP is not blocking port 445, or use Azure P2S VPN, Azure S2S VPN,
  or Express Route to tunnel SMB traffic over a different port."
} 

The Powershell script I have written executes as expected from ‘Sql Server1’. The problem comes into play when I try to run the script from DeployServer via Invoke-Command. The script called via Invoke-Command fails at the Item-Copy command (I have also tried a simple cp command with the same result).

This is the command that fails:

Copy-Item $BackupPath -Destination $NetworkPath -Force –Verbose

This is the error

Cannot find drive. A drive with the name 'Z' does not exist. 

    + CategoryInfo          : ObjectNotFound: (Z:String) [Copy-Item], DriveNotFoundException 

    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.CopyItemCommand 

    + PSComputerName        : sumip

How do I fix the AZ File Share (Z:) so it is available via remote Invoke-Command?

1 Answer 1

0

I could not solve this. Instad I used the Azure Powershell module to copy files to/from Azure. This let me skip the cp step.

https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-powershell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .