Share via

Azure Share DriveNotFoundException Using Powershell

Jeremiah Adams 171 Reputation points
2021-03-22T14:30:56.117+00:00

Azure Share DriveNotFoundException Using Powershell

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 file share 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 Powershell while RDP’d in to SqlServer1.

This is the script (connectivity details obfuscated) I ran to map this drive:

$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 

Anyone have any ideas how to fix the AZ File Share is available via remote Invoke-Command?

Azure Files
Azure Files

An Azure service that offers file shares in the cloud.

0 comments No comments

Answer accepted by question author

Jeremiah Adams 171 Reputation points
2021-03-23T13:33:27.587+00:00

I could not solve this. Instead I used Azure Powershell module to upload to Azure. This let me skip the copy step.

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

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.