Hi,
after few tests I noticed that:
$winVM = Get-Cluster "CL04-VCLOUD02" | Get-VM | Get-VMGuest | Where {$_.OSFullName -match "Windows"} | select -ExpandProperty VMName
filters only VMs with Windows with INSTALLED VMWARE TOOLS. If VM doesn't have intalled vmware tools it won't show up after above command.
I wrote something witch lists me all VMs with Windows OS, but I can't append them to DrsVMGroup.
$winVM = Get-Cluster "CL04-VCLOUD02" |
Get-VM | Sort-Object -Property Name |
Get-View -Property @("Name", "Config.GuestFullName") | Where {$_.Config.GuestFullName -match "Windows"} |
Select -Property Name
Set-DrsVMGroup -Name "grupawindows04" -Cluster "CL04-VCLOUD02" -VM $winVM -Append
I get error:
Set-DrsVMGroup : Cannot validate argument on parameter 'VM'. The "
## make sure that all values are either a String or a VM obj
_Test-TypeOrString -Object $_ -Type ([VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine])
+ Set-DrsVMGroup -Name "grupawindows04" -Cluster "CL04-VCLOUD02" -VM $winVM -Appen ...
+ ~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-DrsVMGroup], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Set-DrsVMGroup
How to do it good? I see that this command can't read and add VMs.
Any help?
That is correct, the VMware Tools need to be installed to get the OS name that way.
You could filter on the OS the user specified when the VM was created.
But there is always a risk that the user installed an altogther different guest OS.
You could make that a bit simpler like this
$winVM = Get-Cluster "CL04-VCLOUD02" |
Get-VM | Where {$_.ExtensionData.Config.GuestFullName -match "Windows"} |
Sort-Object -Property Name |
Select -ExpandProperty Name
Set-DrsVMGroup -Name "grupawindows04" -Cluster "CL04-VCLOUD02" -VM $winVM -Append
The VM parameter expects a string or a VirtualMachine object.
With the Select you're having neither.
You could do
$winVM = Get-Cluster "CL04-VCLOUD02" |
Get-VM | Sort-Object -Property Name |
Get-View -Property @("Name", "Config.GuestFullName") | Where {$_.Config.GuestFullName -match "Windows"}
Set-DrsVMGroup -Name "grupawindows04" -Cluster "CL04-VCLOUD02" -VM $winVM -Append
or
$winVM = Get-Cluster "CL04-VCLOUD02" |
Get-VM | Sort-Object -Property Name |
Get-View -Property @("Name", "Config.GuestFullName") | Where {$_.Config.GuestFullName -match "Windows"} |
Select -ExpandProperty Name
Set-DrsVMGroup -Name "grupawindows04" -Cluster "CL04-VCLOUD02" -VM $winVM -Append
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That is correct, the VMware Tools need to be installed to get the OS name that way.
You could filter on the OS the user specified when the VM was created.
But there is always a risk that the user installed an altogther different guest OS.
You could make that a bit simpler like this
$winVM = Get-Cluster "CL04-VCLOUD02" |
Get-VM | Where {$_.ExtensionData.Config.GuestFullName -match "Windows"} |
Sort-Object -Property Name |
Select -ExpandProperty Name
Set-DrsVMGroup -Name "grupawindows04" -Cluster "CL04-VCLOUD02" -VM $winVM -Append
The VM parameter expects a string or a VirtualMachine object.
With the Select you're having neither.
You could do
$winVM = Get-Cluster "CL04-VCLOUD02" |
Get-VM | Sort-Object -Property Name |
Get-View -Property @("Name", "Config.GuestFullName") | Where {$_.Config.GuestFullName -match "Windows"}
Set-DrsVMGroup -Name "grupawindows04" -Cluster "CL04-VCLOUD02" -VM $winVM -Append
or
$winVM = Get-Cluster "CL04-VCLOUD02" |
Get-VM | Sort-Object -Property Name |
Get-View -Property @("Name", "Config.GuestFullName") | Where {$_.Config.GuestFullName -match "Windows"} |
Select -ExpandProperty Name
Set-DrsVMGroup -Name "grupawindows04" -Cluster "CL04-VCLOUD02" -VM $winVM -Append
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK thanks. It's very helpfull.
Going further I have another problem...
$winVM = Get-Cluster "Cluster-Name" | Get-VM | Where {$_.ExtensionData.Config.GuestFullName -notmatch "vm-name (31246e2b-afb3-45342-92341-ea3b5c094128)"}
$winVMexcludeVm = Get-VM $winVM | Where {$_.ExtensionData.Config.GuestFullName -match "Windows"} | Sort-Object -Property Name |
Select -ExpandProperty Name
$winVMexcludeVm > "C:\Files\test.csv
Name of VM is vm-name (31246e2b-afb3-45342-92341-ea3b5c094128). I want to list all windows OS VMs excluding this "vm-name (31246e2b-afb3-45342-92341-ea3b5c094128)", but every time in test.csv I see this VM... I dont know what I've been doing wrong. Quotas doesnt work well in script or should I use them in different way? Help plz
Provided that Guid is unique, you could try something like this
Get-Cluster "Cluster-Name" | Get-VM | Where {$_.ExtensionData.Config.GuestFullName -notmatch "31246e2b-afb3-45342-92341-ea3b5c094128"} |
Where {$_.ExtensionData.Config.GuestFullName -match "Windows"} | Sort-Object -Property Name |
Select Name |
Export-Csv "C:\Files\test.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It shows me only length of characters in line in file .csv . Any other ideas ?
oops, the ExpandProperty doesn't need to be in there.
I corrected above, try again
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ehhh, file .csv still contains VM which I dont want to see. Do you have any idea why ?
Not really, give it a try with the -notlike operator.
Get-Cluster "Cluster-Name" | Get-VM | Where {$_.ExtensionData.Config.GuestFullName -notlike "*31246e2b-afb3-45342-92341-ea3b5c094128*"} |
Where {$_.ExtensionData.Config.GuestFullName -match "Windows"} | Sort-Object -Property Name |
Select Name |
Export-Csv "C:\Files\test.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Meeh, doesn't work :/... I think, I found some work-around. Add this excluded VM to some DrsVMGroup with rule which will not allow that VM to behave in accordance to that rule(DrsVMGroup) from I cant exclude it.
Sum up - I see that DrsVMGroup rule which hold VM on specific host, wont let this VM to auto-migrate to another host, if the second applied rule tell it to.