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
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
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
yes this is very nice. Thank you
So I would need to manually load the function everytime I use it?
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