Currently, the New-CustomAttribute and Set-Annotation cmdlets do not yet support Datastore objects.
But you can use the CustomFieldsManager methods to cerate and set a CA for a Datatsore.
For example
$dsName = 'MyDS'
$caName = 'DatastoreCA'
$caValue = 'MyValue'
$ds = Get-Datastore -Name $dsName
$caMgr = Get-View CustomFieldsManager
$ca = $caMgr.Field.Where{ $_.Name -eq $caName }
if (-not $ca) {
$ca = $caMgr.AddCustomFieldDef($caName, 'Datastore', $null, $null)
}
$caMgr.SetField($ds.Id, $ca.Key, $caValue)
# Retrieve the CA
$ds.ExtensionData.CustomValue.where{ $_.Key -eq $ca.Key }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Since a CA is defined on the vCenter level, you have 2 options
- set the Value for the CA for a specific datastore to an empty string.
- remove the CA altogether for all Datastores
You can not remove the CA for 1 specific Datastore.
Which of the 2 options do you have in mind?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So why the question if you knew it?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference