Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
param
(
[string]$ServiceName,
[string]$VmName,
[string]$UserName,
[string]$Password
)
$ErrorActionPreference = "Stop"
Write-Host ""
Write-Host " Installing VM Agent on $VmName ($ServiceName)"
Write-Host ""
$uri = (Get-AzureWinRMUri -ServiceName $ServiceName -Name $VmName).ToString()
$securePassword = ConvertTo-SecureString -String $Password -AsPlainText -For
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $securePassword
Write-Host " - WinRM Uri: $uri"
Write-Host " - Connecting to VM using Remote PowerShell."
Write-Host ""
$session = New-PSSession -ConnectionUri $uri -Credential $credential -SessionOption (New-PSSessionOption -SkipCACheck)
Invoke-Command -Session $session -Scriptblock {
Write-Host " > Connected."
$vmAgentInstallationPath = "$env:temp\VmInstallerPath"
New-Item -ItemType Directory -Force -Path $vmAgentInstallationPath | Out-Null
cd $vmAgentInstallationPath
Write-Host " > Download path: $vmAgentInstallationPath"
(New-Object system.net.WebClient).DownloadFile("http://go.microsoft.com/fwlink/p/?LinkId=394789", "$vmAgentInstallationPath\VMAgent.msi");
Write-Host " > Download success."
Write-Host " > Installing..."
Start-Process -FilePath "VMAgent.msi" -ArgumentList "/quiet /l* vmagent-installation.log" -Wait
Write-Host " > Installation complete. The installation logs can be found in the download path."
}
Remove-PSSession $session
Write-Host ""
Write-Host " - VM Agent installed. You can now start exploring the VM Extensions."
Write-Host ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.