こちらの記事の日本語版は作成中となります
How to connect on your Azure Virtual Machine with PowerShell?
First we need to know where is your Azure Virtual Machine public powershell endpoint. In my previous blog, creating Azure Virtual Machine with powershell, I update the powershell endpoint into 5986. however, to find this in Azure Management Portal, just login, select your Virtual Machine and click the “Endpoints” tab.
I created a script on how to connect Azure Virtual Machine with Remote PowerShell which makes a lot easier to setup your VM. Below is the powershell cmdlets I used.
0. Your global variables.
1 2 3 4 5 | $SubscriptionName = "SUBSCRIPTION NAME" $DNSName = "VM DNS NAME" $VMName = "VM NAME" $VMUser = "VM USER" $VMPassword = "VM PASSWORD" |
To get your $SubscriptionName, type in your powershell console
1 | ( Get-AzureSubscription ).SubscriptionName |
1. Add Azure Account Details.
1 2 3 | # The cmdlets need your subscription so they can manage your services. Add-AzureAccount Set-AzureSubscription -SubscriptionName $SubscriptionName |
2. Create a certificate.
Remote Powershell uses HTTPS and the certificate used for your Virtual Machine is a self signed certificate. So, download and install generated certificate into your local certificate store which allows powershell to verify it is communicating with the correct endpoint.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | $WinRMCert = ( Get-AzureVM -ServiceName $CloudServiceName -Name $Name | select -ExpandProperty vm).DefaultWinRMCertificateThumbprint $AzureX509cert = Get-AzureCertificate -ServiceName $CloudServiceName -Thumbprint $WinRMCert -ThumbprintAlgorithm sha1 $certTempFile = [IO.Path] ::GetTempFileName() $AzureX509cert .Data | Out-File $certTempFile If (( Test-Path Cert:\LocalMachine\Root\ $winRMCert ) -eq $false ) { $CertToImport = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $certTempFile $store = New-Object System.Security.Cryptography.X509Certificates.X509Store "Root" , "LocalMachine" $store .Open( [System.Security.Cryptography.X509Certificates.OpenFlags] ::ReadWrite) $store .Add( $CertToImport ) $store .Close() Remove-Item $certTempFile } |
3. Connect to your Azure VM.
1 2 3 | $nVMPassword = convertto-securestring -AsPlainText -Force -String $VMPassword $credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $VMUser , $nVMPassword Enter-PSSession -ComputerName $DNSName ".cloudapp.net" -Port 5986 -Credential $credential -UseSSL |
You are good to go!. Here how I run my script.
Run PowerShell console as Administrator
type Set-ExecutionPolicy RemoteSigned -Force
then .\Connect_AzureVM.ps1

Once you are connected. You can configure now your Virtual Machine. For example installing and configuring Windows Roles, Features, and Services all the way to downloading and deploying an application or website, executing cookbooks, and etc.
See my next blog post on how to execute chef-solo on your Windwos Azure Virtual Machine using Remote PowerShell.
投稿者プロフィール
-
Japan AWS Ambassadors 2023, 2024
開発会社での ASP型WEBサービス企画 / 開発 / サーバ運用 を経て
2010年よりスカイアーチネットワークスに在籍しております
機械化/効率化/システム構築を軸に人に喜んで頂ける物作りが大好きです。
最新の投稿
Amazon Q2025年6月11日Amazon Q Developer CLI でMCPサーバ起動に失敗したのでトラブルシュートしてもらった
AWS2025年2月25日WebスクレイピングにAmazon CloudWatch Synthetics CanaryとBedrockを利用する
AWS re:Invent 20242025年1月1日AWS re:Invent 2024から読み解く、次世代クラウドコンピューティングの潮流
AWS re:Invent 20242024年12月7日Bedrock Flows と Amazon Q Developer Agentの新機能で生成AIアプリを短時間で作成する