{"id":3005,"date":"2015-03-10T16:17:31","date_gmt":"2015-03-10T07:17:31","guid":{"rendered":"http:\/\/www.skyarch.net\/blog\/?p=3005"},"modified":"2024-02-02T13:43:51","modified_gmt":"2024-02-02T04:43:51","slug":"windowsazure%e4%b8%8a%e3%81%aevm%e3%82%92%e3%83%aa%e3%83%a2%e3%83%bc%e3%83%88%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/windowsazure%e4%b8%8a%e3%81%aevm%e3%82%92%e3%83%aa%e3%83%a2%e3%83%bc%e3%83%88%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95\/","title":{"rendered":"WindowsAzure\u4e0a\u306eVM\u3092\u30ea\u30e2\u30fc\u30c8\u64cd\u4f5c\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u3053\u3061\u3089\u306e\u8a18\u4e8b\u306e\u65e5\u672c\u8a9e\u7248\u306f\u4f5c\u6210\u4e2d\u3068\u306a\u308a\u307e\u3059<\/p>\n<h2>How to connect on your Azure Virtual Machine with PowerShell?<\/h2>\n<p>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 \u201cEndpoints\u201d tab.<br \/>\n<a href=\"http:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2015\/03\/Azure-VM-Endpoint.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2961\" src=\"http:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2015\/03\/Azure-VM-Endpoint.png\" alt=\"Azure VM Endpoint\" width=\"819\" height=\"132\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2015\/03\/Azure-VM-Endpoint.png 819w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2015\/03\/Azure-VM-Endpoint-300x48.png 300w\" sizes=\"auto, (max-width: 819px) 100vw, 819px\" \/><\/a><br \/>\nI 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.<\/p>\n<h3>0. Your global variables.<\/h3>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$SubscriptionName = &quot;SUBSCRIPTION NAME&quot;\r\n$DNSName = &quot;VM DNS NAME&quot;\r\n$VMName = &quot;VM NAME&quot;\r\n$VMUser = &quot;VM USER&quot;\r\n$VMPassword = &quot;VM PASSWORD&quot;\r\n<\/pre>\n<p>To get your <strong>$SubscriptionName<\/strong>, type in your powershell console<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n(Get-AzureSubscription).SubscriptionName\r\n<\/pre>\n<h3>1. Add Azure Account Details.<\/h3>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n# The cmdlets need your subscription so they can manage your services.\r\nAdd-AzureAccount\r\nSet-AzureSubscription -SubscriptionName $SubscriptionName \r\n<\/pre>\n<h3>2. Create a certificate.<\/h3>\n<p>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.<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$WinRMCert = (Get-AzureVM -ServiceName $CloudServiceName -Name $Name | select -ExpandProperty vm).DefaultWinRMCertificateThumbprint\r\n$AzureX509cert = Get-AzureCertificate -ServiceName $CloudServiceName -Thumbprint $WinRMCert -ThumbprintAlgorithm sha1\r\n$certTempFile = &#x5B;IO.Path]::GetTempFileName()\r\n$AzureX509cert.Data | Out-File $certTempFile\r\n\r\nIf ((Test-Path Cert:\\LocalMachine\\Root\\$winRMCert) -eq $false) \r\n{ \r\n\t$CertToImport = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $certTempFile\r\n\t$store = New-Object System.Security.Cryptography.X509Certificates.X509Store &quot;Root&quot;, &quot;LocalMachine&quot;\r\n\t$store.Open(&#x5B;System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)\r\n\t$store.Add($CertToImport)\r\n\t$store.Close()\r\n\tRemove-Item $certTempFile\r\n}\r\n<\/pre>\n<h3>3. Connect to your Azure VM.<\/h3>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$nVMPassword= convertto-securestring -AsPlainText -Force -String $VMPassword\r\n$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $VMUser,$nVMPassword\r\nEnter-PSSession -ComputerName $DNSName&quot;.cloudapp.net&quot; -Port 5986 -Credential $credential -UseSSL\r\n<\/pre>\n<p>You are good to go!. Here how I run my script.<br \/>\nRun <strong><em>PowerShell<\/em><\/strong> console as <strong><em>Administrator<\/em><\/strong><br \/>\ntype <strong><em>Set-ExecutionPolicy RemoteSigned -Force<\/em><\/strong><br \/>\nthen <strong><em>.\\Connect_AzureVM.ps1<\/em><\/strong><\/p>\n<a href=\"http:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2015\/03\/Connect-Azure-VM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2971\" src=\"http:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2015\/03\/Connect-Azure-VM.png\" alt=\"Connect Azure VM\" width=\"959\" height=\"328\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2015\/03\/Connect-Azure-VM.png 959w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2015\/03\/Connect-Azure-VM-300x103.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2015\/03\/Connect-Azure-VM-900x308.png 900w\" sizes=\"auto, (max-width: 959px) 100vw, 959px\" \/><\/a>\n<p>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.<\/p>\n<p>See my next blog post on how to execute <strong>chef-solo<\/strong> on your Windwos Azure Virtual Machine using Remote PowerShell.<\/p>\n<p style=\"text-align: left; width: 100%; margin: 0; padding: 0;\"><a href=\"http:\/\/www.skyarch.net\/blog\/?p=2915\"><strong>\u25c4 Windows Azure Virtual Machines with PowerShell<\/strong><\/a><\/p>\n<p style=\"text-align: right; width: 100%; margin: 0; padding: 0;\"><a href=\"https:\/\/www.skyarch.net\/blog\/en\/setup-windows-azure-virtual-machines-with-remote-powershell\/\"><strong>Azure VM - CHEF - PowerShell \u25ba<\/strong><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3061\u3089\u306e\u8a18\u4e8b\u306e\u65e5\u672c\u8a9e\u7248\u306f\u4f5c\u6210\u4e2d\u3068\u306a\u308a\u307e\u3059 How to connect on your Azure Virtual Machine with PowerShell? First we need to know where&#8230;<\/p>\n","protected":false},"author":2,"featured_media":2948,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"2956","footnotes":""},"categories":[88,83,18,30],"tags":[],"class_list":{"0":"post-3005","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-azure","8":"category-devops","9":"category-os","10":"category-windows","11":"ja"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/3005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/comments?post=3005"}],"version-history":[{"count":2,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/3005\/revisions"}],"predecessor-version":[{"id":25797,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/3005\/revisions\/25797"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/2948"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=3005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=3005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=3005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}