Hey,
I need to create a VM using a pre-configured OVF template which is stored in the content library on our vCenter.
My question is how can I do this through powercli scripting?
in the last step of manual installation(attached), it asks for the SSH key, domain name, IP, etc. I wonder if it is possible to pass these properties through Powercli and deploy the VM?
Thanks
Aren't these OVF Configuration settings that you can retrieve with Get-OvfConfiguration?
Then use the New-VM with the ContentLibraryItem and OvfConfiguration parameters.
See Example 2 on Get-OvfConfiguration
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey LucD,
Thanks, yes, I was not able to find the path for OVF template since it was starting like /root/...
Anyway, I have downloaded the OVF configuration file and here is the properties section:
<ProductSection>
<Info>VM Arguments</Info>
<Category>VM Properties</Category>
<Property ovf:userConfigurable="true" ovf:type="string" ovf:key="va-ssh-public-key">
<Label>Set the SSH public key allowed to access the appliance</Label>
<Description>This will enable the SSHD service and configure the specified public key for the user 'username'</Description>
</Property>
<Property ovf:userConfigurable="true" ovf:type="string" ovf:key="user-data">
<Label>User data to be made available inside the instance</Label>
<Description>This allows to pass any text to the appliance. It will be executed if it starts with a shebang ("#!"). The value should be encoded in base64</Description>
</Property>
<Category>Networking Properties</Category>
<Property ovf:userConfigurable="true" ovf:type="string" ovf:key="network.gateway">
<Label>Default Gateway</Label>
<Description>The default gateway address for this VM. Leave blank if DHCP is desired</Description>
</Property>
<Property ovf:userConfigurable="true" ovf:type="string" ovf:key="network.domain">
<Label>Domain Name</Label>
<Description>The domain name of this VM. Leave blank if DHCP is desired</Description>
</Property>
<Property ovf:userConfigurable="true" ovf:type="string" ovf:key="network.searchpath">
<Label>Domain Search Path</Label>
<Description>The domain search path (comma or space separated domain names) for this VM. Leave blank if DHCP is desired</Description>
</Property>
<Property ovf:userConfigurable="true" ovf:type="string" ovf:key="network.dns">
<Label>Domain Name Servers</Label>
<Description>The domain name server IP Addresses for this VM (comma separated). Leave blank if DHCP is desired</Description>
</Property>
<Property ovf:userConfigurable="true" ovf:type="string" ovf:key="network.ip0">
<Label>Network 1 IP Address</Label>
<Description>The IP address for this interface. Leave blank if DHCP is desired</Description>
</Property>
<Property ovf:userConfigurable="true" ovf:type="string" ovf:key="network.netmask0">
<Label>Network 1 Netmask</Label>
<Description>The netmask or prefix for this interface. Leave blank if DHCP is desired</Description>
</Property>
</ProductSection>
Hope this is enough, so how should I use these to pass the properties through powercli? OvfConfiguration parameters I mean.
Alos, please tell me where is these OVF templates stored at /root/.. ? what is the default path?
Thanks
Did you use the Get-ContentLibraryItem cmdlet?
The returned object can be used on the ContentLibraryItem parameter of the Get-OvfConfiguration cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Whem I use Get-ContentLibraryItem it just show the details of this item that includes my tempates:
PS C:\Users\Polaris> Get-ContentLibrary -Name "new"
Name Type Published Password
Protected
---- ---- --------- ----------
new Subscribed False
Also, the cmdlet Get-OvfConfiguration only reads my own computer directories, not from vcenter/vsphere even I'm connected [to Connect-VIServer]!
Anyway, I have downloaded the OVF configuration file from vcenter to my own computer and used Get-OvfConfiguration as below:
PS C:\Users\Polaris> Get-OvfConfiguration -Ovf "C:\Users\Polaris\Downloads\temp-wp-7bb648-ce2b-4bf7-a747-e897867b4d9c.ovf"
================================================================
OvfConfiguration: temp-wp-7bb648-ce2b-4bf7-a747-e897867b4d9c.ovf
Properties:
-----------
Common
NetworkMapping
it just shows above details as properties! so, how should I use these to create a VM with this temaplet and pass properties?
Am I missing something here in using these cmdlet(s)?
Are you actually reading my replies?
You are not using the ContentLibraryItem parameter on the Get-OvfConfiguration cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dear LucD, I tried that, but that parameter (ContentLibraryItem) is not available in Get-OvfConfiguration cmdlet in my PS!
As you mentioned, here are two kinds of syntax for Get-OvfConfiguration:
OVF: Parameters are available for me
FromLibraryItem: Parameters are not available for me
(attached)
here is my PS version:
PS C:\WINDOWS\system32> Get-PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 22000 613
PS C:\WINDOWS\system32> Get-PowerCLIVersion
WARNING: The cmdlet "Get-PowerCLIVersion" is deprecated. Please use the 'Get-Module' cmdlet instead.
PowerCLI Version
----------------
VMware PowerCLI 12.1.0 build 17009493
---------------
Component Versions
---------------
VMware Common PowerCLI Component 12.1 build 16997174
VMware Cis Core PowerCLI Component PowerCLI Component 12.1 build 16997582
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.1 build 16997984
Please tell me if I'm using the cmdlet in a wrong way.
Then you should probably first try to upgrade your PowerCLI installation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey LucD
I could get that fixed and now Im able to use that Cmdlet
PS /root> Get-OvfConfiguration -ContentLibraryItem $item -Target $hostname
==============================================================================
OvfConfiguration: wordpresspro-5.9.3-11-r04-linux-centos-7-x86_64-nami
Properties:
-----------
Common
EULAs
IpAssignment
Name
NetworkMapping
Size
But when I check this with the manuall setup(attached) and ovf-configuration file (attached), it shows different properties as fields or as key!
.
It shows some properties which need to pass through the below command I guess, but I just used one of those as test:
$dns="8.8.8.8"
$ovfconfig=@{"network.dns"=$dns}
New-VM -ContentLibraryItem $item -OvfConfiguration $ovfconfig -VMHost $host
New-VM: 6/14/2022 1:53:53 PM New-VM com.vmware.vcenter.ovf.ovf_error {'category': INPUT, 'issues': , 'name': EulaParams.all_EULA_accepted, 'value': false, 'message': com.vmware.vapi.std.localizable_message {'id': com.vmware.ovfs.ovfs-main.ovfs.invalid_ovf_parameter, 'default_message': Invalid value for EulaParams.all_EULA_accepted: false., 'args': [EulaParams.all_EULA_accepted, false], 'params': , 'localized':}, 'error':}
Im not sure how should I use those properties to deploy the VM using this template.
I hope you give me some clue as always.
Thanks
Brian wrote a good intro to the Get-OvfConfiguration cmdlet, see PowerCLI 5.8 New Feature: Get-OvfConfiguration (Part 1 of 2)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference