Ok, so I have it working to import the OVF files by the name that they already have. However in my script I want to move them to a different folder, but I don't know what name to use for the VM. Here's the code that I have:
Get-ChildItem -Path $folderpath -Directory | ForEach-Object -Process {
Get-ChildItem -Path $_.FullName -File -Filter *.ovf | ForEach-Object -Process {
Import-vApp -Source $_.FullName -VMHost $vmHost.Name -Location $myCluster -DiskStorageFormat $diskStorage -Datastore $mydatastore
}
}
Sleep 10
$folder = Get-Datacenter -Name $dc.Name | Get-Folder -Type VM | sort Name | Out-GridView -Title 'Select a VM folder to move to' -OutPutMode Single
$VMmove = $folder.Name
Move-VM -VM $vmName -Destination $VMmove #Moves VM to the appropriate folder#
if($myCluster){
$vlans = Get-Cluster -Name $mycluster.Name | Get-VMHost -Name $vmHost.Name | Foreach-Object {Get-VirtualPortGroup $_ | Select-Object @{N="Cluster";E={$cluster.Name}},Name,VLanId} | Out-GridView -Title 'Select a VLAN' -OutputMode Single #Gets available VLANs from the host#
}
else{
$vlans = Get-VMHost -Name $vmHost.Name | Foreach-Object {Get-VirtualPortGroup $_ | Select-Object @{N="Cluster";E={$cluster.Name}},Name,VLanId} | Out-GridView -Title 'Select a VLAN' -OutputMode Single #Gets available VLANs from the host#
}
$vlan = $vlans
$NIC = Get-NetworkAdapter -VM $folderPath.Name
Set-NetworkAdapter -NetworkAdapter $NIC -NetworkName $vlan.Name -Confirm:$false #Applies selected VLAN to VM#
So basically after the import I want to get a folder to move them to and then move them there. However I haven't specified a VM name anywhere. I did originally in the script after I had selected the file to import, but since I'm doing multiple OVF's I just want to use the name associated with them. Would the $_.FullName work somehow or is there a better way to get the multiple VM names?