AndreiM
AndreiM

Reputation: 886

How to RDP connect to an Azure VM

I would like to run some tests on some VM machines. The machines belong to different users with different MSDN accounts, which means private passwords.

What I did was so far is to create an Azure VM for each MSDN account and set a similar user name/password for the machine.

What I would like to do is to:

  1. Connect to any of these VMs. My problem: I don't know the machine name. I tried to connect using the rdp file provided by Azure, and it's working, but the problem is that it's using an IP instead of a name. I tried finding the machine name, but all documentation about this seems to be outdated. This is how my machine description looks like. I tried to connect to amam10x64.westeurope.cloudapp.azure.com but without success.

  2. Copy a file to/from the VM. My hope is that I can use the following snippet:

    $commandStr = [string]::Format("Copy-VMFile ""{0}"" -SourcePath ""{1}"" - DestinationPath ""{2}"" -CreateFullPath -FileSource Host -Force", $VM, $SessionPath, $RemoteFullPath) $commandBlock = [scriptblock]::Create($commandStr) Invoke-Command -Session $sess -ScriptBlock $commandBlock

  3. Run a command on the VM. Hopefully, I can use same command from Pt. 2.

Upvotes: 0

Views: 837

Answers (1)

Jason Ye
Jason Ye

Reputation: 13974

I tried to connect to amam10x64.westeurope.cloudapp.azure.com but without success.

If you want to connect this VM with DNS, we should set FQDN for this VM, please refer to this link.

Copy a file to/from the VM. My hope is that I can use the following snippet:

Maybe we can use winrm to do this. About how to use winrm connect Azure VM, please refer to this answer.

Run a command on the VM. Hopefully, I can use same command from Pt. 2.

We can use this script to connect Azure VM via Winrm:

$username = 'jason'
$pass = ConvertTo-SecureString -string 'password' -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $pass
$s = New-PSSession -ConnectionUri 'http://23.99.82.2:5985' -Credential $cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
Invoke-Command -Session $s -ScriptBlock {Get-Process PowerShell}

Upvotes: 1

Related Questions