VMware Cloud Community
tdubb123
Expert
Expert
Jump to solution

script to import ovf with param

trying to get a script working for importing ovf for multiple locations

any idea how i can do it with params

params are

$datastore = get-datastore -name "myDS"

$vmHost = Get-VMHost -Name "MyHost"

Import-vApp -Source 'C:\my.ova' -Datastore $myDatastore -vmhost $vmhost -Force

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Do you mean something like this, i.e. a function?

function My-OvfImport{
  param(
    [string]$OvfSource,
    [string]$Datastore,
    [string]$VMHost
  )

  $ds = Get-Datastore -Name $Datastore
  $esx = Get-VMHost -Name $VMHost

  Import-VApp -Source $OvfSource -Datastore $ds -VMHost $esx -Force
}

My-OvfImport -OvfSource 'C:\MyOva1' -VMHost 'MyEsx1' -Datastore 'MyDatastore1'
My-OvfImport -OvfSource 'C:\MyOva2' -VMHost 'MyEsx1' -Datastore 'MyDatastore2'

 


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

View solution in original post

3 Replies
LucD
Leadership
Leadership
Jump to solution

Do you mean something like this, i.e. a function?

function My-OvfImport{
  param(
    [string]$OvfSource,
    [string]$Datastore,
    [string]$VMHost
  )

  $ds = Get-Datastore -Name $Datastore
  $esx = Get-VMHost -Name $VMHost

  Import-VApp -Source $OvfSource -Datastore $ds -VMHost $esx -Force
}

My-OvfImport -OvfSource 'C:\MyOva1' -VMHost 'MyEsx1' -Datastore 'MyDatastore1'
My-OvfImport -OvfSource 'C:\MyOva2' -VMHost 'MyEsx1' -Datastore 'MyDatastore2'

 


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

tdubb123
Expert
Expert
Jump to solution

yes this is very nice. Thank you

 

So I would need to manually load the function everytime I use it?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you stay in the same PowerShell/PowerCLI session, you only need to dot-source the .ps1 file containing the function once.
You can then call the function, in the same session, multiple times.


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

0 Kudos