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:
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
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 : PropertyNotFoundCreated By: UnknownMethod invocation failed because [System.Object[]] doesn't contain a method named 'setCustomValue'.At U:\Scripts\vm2vc-pm.ps1:69 char:26+ $vmView.setCustomValue <<<< ("Created By", $vmStartUser)+ CategoryInfo : InvalidOperation: (setCustomValue:String) [], RuntimeException+ FullyQualifiedErrorId : MethodNotFoundCreated Date: UnknownMethod invocation failed because [System.Object[]] doesn't contain a method named 'setCustomValue'.At U:\Scripts\vm2vc-pm.ps1:73 char:26+ $vmView.setCustomValue <<<< ("Created Date", $vmStartDate)+ CategoryInfo : InvalidOperation: (setCustomValue:String) [], RuntimeException+ FullyQualifiedErrorId : MethodNotFoundTemplate Source Name: autodev02Method invocation failed because [System.Object[]] doesn't contain a method named 'setCustomValue'.At U:\Scripts\vm2vc-pm.ps1:78 char:26+ $vmView.setCustomValue <<<< ("Template Source Name", $vmStartTemplate)+ CategoryInfo : InvalidOperation: (setCustomValue:String) [], RuntimeException+ FullyQualifiedErrorId : MethodNotFoundnow 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/