I've been using this script for about a month, been working fine, then all of a sudden it stops working.
$Datastores = "CBE_TO_QTS_VMMigration_OS_01"
$VMFolder = "TEST"
$ESXHost = Get-Cluster $Cluster | Get-VMHost | select -First 1
foreach($Datastore in Get-Datastore $Datastores) {
# Set up Search for .VMX Files in Datastore
$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 $VMFolder -RunAsync
}
}
I get this everytime. The datastore is mounted to all the host in the cluster.
Exception calling "SearchDatastoreSubFolders" with "2" argument(s): "Invalid datastore path '[CBE_TO_QTS_VMMigration_OS_01 CBE_TO_QTS_VMMigration_OS_01 CBE_TO_QTS_VMMigration_OS_01
| CBE_TO_QTS_VMMigration_OS_01]'."
Any guesses or suggestions?
It looks like that datastorename is in there 4 times.
Do you have multiple vCenter connections open?
Check what is in $global:defaultviservers
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It looks like that datastorename is in there 4 times.
Do you have multiple vCenter connections open?
Check what is in $global:defaultviservers
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That was it, I was connected to the same vCenter twice using seperate credentials..
Thanks so much, as always..