title: Set-AzureRmVMCustomScriptExtension before Creating VM
body: <p>When running the below Azure Powershell, I get error: </p>
  
  <blockquote>
    <p>Set-AzureRmVMCustomScriptExtension : Can not perform requested
    operation on nested resource. Parent resource 'mycomputer' not found.</p>
  </blockquote>
  
  <pre><code>$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
  </code></pre>
  
  <p>Can I not set the CustomScriptExtension as part of building the New VM?</p>