Another solution is to use the Custom Script Extension .
Using a custom script extension allows you to copy a file to a virtual machine, even if the virtual machine does not have an open IP address (private network). Therefore, you do not need to configure winRm or anything else.
I used my own extension scripts in the past for post-deployment, such as installing an application on a virtual machine or a set of scales. Basically you upload files to the blob repository, and the custom script extension uploads these files to the virtual machine.
I created test-container on my blob memory account and uploaded two files:
deploy.ps1 : script executed in a virtual machine.test.txt : text file with "Hello world from VM"
Here is the code for the deploy.ps1 file:
Param( [string] [Parameter(Mandatory=$true)] $filename, [string] [Parameter(Mandatory=$true)] $destinationPath )
Here is the code for adding a custom script extension to a virtual machine.
Login-AzureRMAccount $resourceGroupName = "resourcegroupname" $storageAccountName = "storageaccountname" $containerName = "test-container" $location = "Australia East" $vmName = "TestVM" $extensionName = "copy-file-to-vm" $filename = "test.txt" $deploymentScript = "deploy.ps1" $destintionPath = "C:\MyTempFolder\" $storageAccountKeys = (Get-AzureRmStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName).Value $storageAccountKey = $storageAccountKeys[0] Set-AzureRmVMCustomScriptExtension -ResourceGroupName $resourceGroupName -VMName $vmName -Name $extensionName -Location $location -TypeHandlerVersion "1.9" -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey -ContainerName $containerName -FileName $deploymentScript, $filename -Run $deploymentScript -Argument "$filename $destintionPath" -ForceRerun "1"
You can remove the extension after copying the file:
Remove-AzureRmVMCustomScriptExtension -ResourceGroupName $resourceGroupName -VMName $vmName -Name $extensionName -Force
In my scenario, I have a logical application that runs every time a new file is added to the container. The logical application calls the runbook (an azure automation account is required), which adds a custom script extension and then removes it.
Thomas
source share