Get-AzureRemoteDesktopFile Access to the path is denied

Get-AzureRemoteDesktopFile Access to the path is denied

You can quickly and easily download .RDP connection files for VMs in Azure via powershell using the Get-AzureRemoteDesktopFile cmdlet.

While using this cmdlet you may encounter an Access to the path is denied error as shown below:

$serviceName = "jakesNewService"
$vmName = "jakesfirstVM"
$path = "C:\rs-pkgs"
Get-AzureRemoteDesktopFile -ServiceName $serviceName -Name $vmName -LocalPath $path
Get-AzureRemoteDesktopFile Access to the path is denied.
At \\192.168.1.200\techstore\SysAdmin\Azure\PS\VMs\GetRDPFile.ps1:6 char:1
+ Get-AzureRemoteDesktopFile -ServiceName $serviceName -Name $vmName -LocalPath $p ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureRemoteDesktopFile], UnauthorizedAccessException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.GetAzureRemoteDesktopFileCommand

This is due to not specifying the name of the .rdp file in the $path variable. This can be resolved by including the name of the .rdp file as shown in the below example:

$serviceName = "jakesNewService"
$vmName = "jakesfirstVM"
$path = "C:\rs-pkgs\jakesvm.rdp"
Write-Host $serviceName
Get-AzureRemoteDesktopFile -ServiceName $serviceName -Name $vmName -LocalPath $path
OperationDescription        OperationId                             OperationStatus
--------------------        -----------                             ---------------
Get-AzureRemoteDesktopFile  c31ae120-7a33-bded-b3a4-9052ad7ae569     Succeeded

Leave a Reply

Your email address will not be published.