Set-AzureRmVMCustomScriptExtension before Creating VM

powershell azure azure-virtual-machine

382 观看

2回复

908 作者的声誉

When running the below Azure Powershell, I get error:

Set-AzureRmVMCustomScriptExtension : Can not perform requested operation on nested resource. Parent resource 'mycomputer' not found.

$vm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize
$vm = Set-AzureRmVMSourceImage -VM $vm -Id $image.Id
$vm = Set-AzureRmVMOSDisk -VM $vm -StorageAccountType $vmStorageType -DiskSizeInGB $vmDiskSize -CreateOption FromImage -Caching ReadWrite
$vm = Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $vmName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
$vm = Add-AzureRmVMSecret -VM $vm -SourceVaultId $vaultId -CertificateStore "My" -CertificateUrl $certURL
$vm = Set-AzureRmVMCustomScriptExtension -ResourceGroupName $rsgName -VMName $vmName -Name $extenstionName -Location $location -StorageAccountName $storageName -StorageAccountKey $storageKey -FileName $fileName -ContainerName $containerName -Run $fileName
$vm = New-AzureRmVM -VM $vm -ResourceGroupName $rsgName -Location $location

Can I not set the CustomScriptExtension as part of building the New VM?

作者: Jeffrey 的来源 发布者: 2017 年 12 月 27 日

回应 2


0

41514 作者的声誉

The Set-AzureRmVMCustomScriptExtension command can be used to add the Custom Script extension to an existing virtual machine. Existing VM. so no, you cannot do that before creating a VM.

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/extensions-customscript#powershell-deployment

作者: 4c74356b41 发布者: 2017 年 12 月 27 日

0

14654 作者的声誉

VM custom script extension is a separate task that need create VM firstly. So, just adjust the execution order of your script.

##create a VM, no need $vm
New-AzureRmVM -VM $vm -ResourceGroupName $rsgName -Location $location
##create custom script extension
Set-AzureRmVMCustomScriptExtension -ResourceGroupName $rsgName -VMName $vmName -Name $extenstionName -Location $location -StorageAccountName $storageName -StorageAccountKey $storageKey -FileName $fileName -ContainerName 
作者: Shui shengbao 发布者: 2017 年 12 月 28 日
32x32