Skip to content

Instantly share code, notes, and snippets.

@sandrinodimattia
Created April 10, 2014 21:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sandrinodimattia/10425245 to your computer and use it in GitHub Desktop.
Save sandrinodimattia/10425245 to your computer and use it in GitHub Desktop.
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