Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update/extend expirationDate of an existing DevTest lab VM that already has one set? #776

Open
slime-uk opened this issue Jun 7, 2021 · 2 comments

Comments

@slime-uk
Copy link

slime-uk commented Jun 7, 2021

Hi,

Searching the internet we found some articles regarding how to use Azure PowerShell to extend a date on a lab VM for expiry.

Examples:

  1. https://github.com/Azure-Samples/virtual-machines-powershell-auto-expired/blob/master/README.md
  2. https://social.msdn.microsoft.com/Forums/azure/en-US/72034bf9-37c9-464e-8c2f-2ca9b9424a4c/how-to-change-or-postpone-a-vm-expiration-datetime-?forum=AzureDevTestLabs
  3. https://feedback.azure.com/forums/320373-lab-services/suggestions/34793482-postpone-expiration-date-for-individual-vms-if-nee
  4. https://azure.microsoft.com/en-gb/blog/set-expiration-date-for-vms-in-azure-devtest-labs/
    etc.

So, a lab user created a VM with 24 hr expiry and now wishes to keep it longer due to testing which has not concluded.
Whatever we try we just get the following error back on the Set-AzureRmResource command:

Set-AzureRmResource : MissingRequiredProperties : One of the following properties must be specified: customImageId, galleryImageReference.

Note our lab VM is created from an ARM template and from a lab attached shared image gallery (so a custom image in our private shared image gallery, not a public/marketplace image). As it's a private shared image gallery, it's not a true lab custom image either as such. So, in our ARM template we do not provide gallery reference or custom image ID, but more SharedImageID and SharedImageVersion.

We have tried to provide null values, or what we think may be suitable values for the "missing" properties but then we get error Set-AzureRmResource : CannotSetProperty : Cannot set or update property galleryImageReference. or Set-AzureRmResource : CannotSetProperty : Cannot set or update property customImageId.

Using AzureRm 6.13.1 but also tried Az in pwsh core and same issue.

Note that we get this error if we just get the VM object (using Get-AzureRmResource) change no properties and then set it back using Set-AzureRmResource.

Thanks!

@leovms leovms added the question label Jun 8, 2021
@petehauge
Copy link
Collaborator

Hi - Good question, this is probably because of the API Version. There are some properties that have been added in a later API version. To resolve this, you can either:

  1. First get the object, modify properties and write it back, or
  2. Specify the API version

I have a handy script for updating the expiration date (prompts you for resources) that might be helpful, take a look at the attached!

Extend-DtlLabVmExpiration.zip

@slime-uk
Copy link
Author

Thanks and sorry for the delay in my response. 1. I have tried to get the object, modify and set back and I get the error I described. It will not allow it as the object get does not seem complete (possibly for the API version I am using). I also tried to get, make no modifications and set back with the same error.

  1. I will have a look at your script - many thanks for providing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants