Can one show how to combined the script from hrobison and the script from run-virtual.com
At the end of the thread http://communities.vmware.com/thread/115635?tstart=0 is script exprintcustomfield.com
From the script http://www.run-virtual.com/files/vi3_diskfree.zip I took the part
that creates the custom field:
if (defined $customFieldsManager->{field}) #---- Are there any custom fields?
{
my $fields = $customFieldsManager->{field};
foreach(@$fields) #---- Check existing custom fields if 'DiskFree' or 'DiskFree%' exists
{
#print "Field name:\t" . $_->name . "\n";
if ($_->name eq "DiskFree")
{
$diskFreeKey = $_->key;
}
if ($_->name eq "DiskFree%")
{
$diskPercentKey = $_->key;
}
if ($_->name eq "DiskFree Alert")
{
$diskAlertKey = $_->key;
}
}
}
if ($diskFreeKey == -1 ) #---- If no custom field called 'DiskFree' is found, let's create it
{
my $result = $customFieldsManager-> AddCustomFieldDef(name=>"DiskFree");
$diskFreeKey = $result->key;
}
if ($diskPercentKey == -1 ) #---- If no custom field called 'DiskFree%' is found, let's create it
{
my $result = $customFieldsManager-> AddCustomFieldDef(name=>"DiskFree%");
$diskPercentKey = $result->key;
}
if ($diskAlertKey == -1 ) #---- If no custom field called 'DiskFree Alert' is found, let's create it
{
my $result = $customFieldsManager-> AddCustomFieldDef(name=>"DiskFree Alert");
$diskAlertKey = $result->key;
}
The problem part is to get the value in the field. It is $thisVM variable.
$customFieldsManager -> SetField(entity => $thisVM,
key=> $diskFreeKey,
value => int($diskFreeTotalMB). " MB"
);
At the end of the thread http://communities.vmware.com/thread/115635?tstart=0 is script exprintcustomfield.com
From the script http://www.run-virtual.com/files/vi3_diskfree.zip I took the part
that creates the custom field:
if (defined $customFieldsManager->{field}) #---- Are there any custom fields?
{
my $fields = $customFieldsManager->{field};
foreach(@$fields) #---- Check existing custom fields if 'DiskFree' or 'DiskFree%' exists
{
#print "Field name:\t" . $_->name . "\n";
if ($_->name eq "DiskFree")
{
$diskFreeKey = $_->key;
}
if ($_->name eq "DiskFree%")
{
$diskPercentKey = $_->key;
}
if ($_->name eq "DiskFree Alert")
{
$diskAlertKey = $_->key;
}
}
}
if ($diskFreeKey == -1 ) #---- If no custom field called 'DiskFree' is found, let's create it
{
my $result = $customFieldsManager-> AddCustomFieldDef(name=>"DiskFree");
$diskFreeKey = $result->key;
}
if ($diskPercentKey == -1 ) #---- If no custom field called 'DiskFree%' is found, let's create it
{
my $result = $customFieldsManager-> AddCustomFieldDef(name=>"DiskFree%");
$diskPercentKey = $result->key;
}
if ($diskAlertKey == -1 ) #---- If no custom field called 'DiskFree Alert' is found, let's create it
{
my $result = $customFieldsManager-> AddCustomFieldDef(name=>"DiskFree Alert");
$diskAlertKey = $result->key;
}
The problem part is to get the value in the field. It is $thisVM variable.
$customFieldsManager -> SetField(entity => $thisVM,
key=> $diskFreeKey,
value => int($diskFreeTotalMB). " MB"
);