VMware Cloud Community
pmeqix
Contributor
Contributor

vm2vc-created related info needed

I have the vm2vc script however it appears to be creating the "createdby" and "created date" attributes before it updates the same for each VM.. however I already have the following attributes and would like to use them to update the information.. what do i need to modify to make this happen.

Also i have "template source name" attribute that also I would like to update based on the "vmDeployment" and "vmCloned' events that can provide the source template or VM of which the desitination VM was created off of.

any help is highly appreciated..

for tracking purposes:

  1. Original post for this script
    http://communities.vmware.com/people/jwmarrott/blog/2011/07/06/update-created-by-and-created-date-cu...
  2. Copy of the script -- attached
0 Kudos
2 Replies
LucD
Leadership
Leadership

The script uses the attributes called "Created By","Created Date".

If I understand it correctly you want to use other names for the Custom Attributes.

To use your names, update the line

$inAttribs = "Created By","Created Date"

by

$inAttribs = "createdBy","creationDate"

where you replace with your names of course.

Try the attached updated script, it should create a "Template" custom attribute.


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

0 Kudos
pmeqix
Contributor
Contributor

Hi LucD

I am getting following errors when i Run the script and it appears to be taking the wrong template source name.

Property '' cannot be found on this object; make sure it exists and is settable
.
At U:\Scripts\vm2vc-pm.ps1:64 char:18
+             $vmattribinfo. <<<< ($tmpattribname.Name) = $vmcustattrib.Value
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
        Created By: Unknown
Method invocation failed because [System.Object[]] doesn't contain a method nam
ed 'setCustomValue'.
At U:\Scripts\vm2vc-pm.ps1:69 char:26
+             $vmView.setCustomValue <<<< ("Created By", $vmStartUser)
    + CategoryInfo          : InvalidOperation: (setCustomValue:String) [], Ru
   ntimeException
    + FullyQualifiedErrorId : MethodNotFound
        Created Date: Unknown
Method invocation failed because [System.Object[]] doesn't contain a method nam
ed 'setCustomValue'.
At U:\Scripts\vm2vc-pm.ps1:73 char:26
+             $vmView.setCustomValue <<<< ("Created Date", $vmStartDate)
    + CategoryInfo          : InvalidOperation: (setCustomValue:String) [], Ru
   ntimeException
    + FullyQualifiedErrorId : MethodNotFound
        Template Source Name: autodev02
Method invocation failed because [System.Object[]] doesn't contain a method nam
ed 'setCustomValue'.
At U:\Scripts\vm2vc-pm.ps1:78 char:26
+             $vmView.setCustomValue <<<< ("Template Source Name", $vmStartTemp
late)
    + CategoryInfo          : InvalidOperation: (setCustomValue:String) [], Ru
   ntimeException
    + FullyQualifiedErrorId : MethodNotFound

now that i am looking at this what i would rather like to do is, take a csv file as input which has the VM-Name and all the custome attributes that I need updated and use that to run a script and update the attributes.

is that a simple fix to this script?

or would it be much easier to use your sample as below to make that happen?

# Import all custom attributes from a CSV file (restore)
Import-Csv “C:\CA-backup.csv” | %{
$vmArray[$_.VmName].Object.setCustomValue($_.CAName,$_.CAValue)
}

Source of the above sample:

http://www.virtu-al.net/2009/05/29/powercli-on-steroids-custom-attributes/

0 Kudos