Hi,
I have below code working if I have existing vmfolder input, when want to add VM to inventory of cluster consisting data stores.
But, I want VM to be added to single esxihost directly and not to any existing vmfolder.
What I should pass in Location argument? Please help.
$esxihost = "10.xxx.xx.xx"
Connect-VIServer $esxihost
#$VMFolder = "Snap-Mirror"
$vm = @("Auto1.xxx.xxx.local")
$ESXHost = Get-VMHost $esxihost
#Write-Output $ESXHost
$Datastores = $ESXHost | Get-Datastore
#Write-Output $Datastores
# Set up Search for .VMX Files in Datastore
foreach($Datastore in $Datastores) {
$ds = Get-Datastore -Name $Datastore | %{Get-View $_.Id}
$SearchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$SearchSpec.matchpattern = "*.vmx"
$dsBrowser = Get-View $ds.browser
$DatastorePath = "[" + $ds.Summary.Name + "]"
# Find all .VMX file paths in Datastore, filtering out ones with .snapshot (Useful for NetApp NFS)
$SearchResult = $dsBrowser.SearchDatastoreSubFolders($DatastorePath, $SearchSpec) | where {$_.FolderPath -notmatch ".snapshot"} | %{$_.FolderPath + ($_.File | select Path).Path}
#Register all .vmx Files as VMs on the datastore
foreach($VMXFile in $SearchResult) {
New-VM -VMFilePath $VMXFile -VMHost $ESXHost -Location $ESXhost.Id -RunAsync
#New-VM -Confirm:$false -Verbose:$true -Name $vm -VMHost $ESXHost -VMFilePath "[$dsv1] $vm/$vm.vmx"
} }
} }
Thanks