VMware Cloud Community
bkolaske
Contributor
Contributor
Jump to solution

Script to update custom attribute

I am currently trying to create a script that will get the whencreated date from AD and then populate a custom attribute (called BuildDate) with the information. If I try to run the script below i get "Value is a read only property". If I look at the values without trying to set them I can see the information. Any assistance would be appreciated.

$vm = Get-VM -Name vmname

$cdate = Get-QADComputer -Name $vm

foreach ($field in $vm.CustomFields)

{

if ($field.Key -eq "BuildDate")

{$field.Value = $cdate.whencreated

}

}

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The VI Toolkit contains cmdlets (New-CustomField, Set-CustomField, Remove-CustomField) to manipulate the custom attributes.

Did you try using those ?

You can't write to the SDK properties like that.

You have to use the SDK methods to change settings.

But like I said, there is in fact no need to use the SDK, you can use the VITK cmdlets.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

The VI Toolkit contains cmdlets (New-CustomField, Set-CustomField, Remove-CustomField) to manipulate the custom attributes.

Did you try using those ?

You can't write to the SDK properties like that.

You have to use the SDK methods to change settings.

But like I said, there is in fact no need to use the SDK, you can use the VITK cmdlets.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
bkolaske
Contributor
Contributor
Jump to solution

Worked like a charm. Thanks for your input.

Reply
0 Kudos