Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
powershell [2018/06/19 17:54] – external edit 127.0.0.1powershell [2021/04/01 11:24] (current) – [Alle VMs eines Datastores im Inventory registrieren] mschubi
Line 50: Line 50:
 PowerCLI ist die CMDlet Erweiterung der Powershell von VMware um eine VMware ESX/VI3/vSphere/wieauchimmer Umgebung effizient zu managen. Es gibt für fast alles fertige CMDlets und wenn die nicht reichen, kann man ja immer noch direkt auf die API gehen. PowerCLI ist die CMDlet Erweiterung der Powershell von VMware um eine VMware ESX/VI3/vSphere/wieauchimmer Umgebung effizient zu managen. Es gibt für fast alles fertige CMDlets und wenn die nicht reichen, kann man ja immer noch direkt auf die API gehen.
  
 +
 +===== Alle VMs eines Datastores im Inventory registrieren =====
 +
 +<code powershell>
 +$VMFolder = "test"
 +$vmhost = "esxhost"
 +$DatastoreName = get-vmhost $vmhost | Get-Datastore | where {$_.Name -like "snap*"}
 +
 +ForEach($regDS in $DatastoreName){
 +
 +$ds = Get-Datastore -Name $regDS | %{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 -ResourcePool $vmhost -Location $VMFolder -RunAsync }}
 +
 +</code>
  
 ==== Was sind primary HA Nodes? ==== ==== Was sind primary HA Nodes? ====
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International