I am training my power shell skiils and challenging my abilities, i need you assist with the following easy task.
I want to get any VM and his own cluster on PowerCLI.
I know that i can get this details using HOST.PARENT but i insist to get this details via “Cluster” in order to learn work with two for each, for some reason it doesn’t work for me, can you assist?
If you want to find the VMs within each cluster, you can the following with calculated properties:
# Get all clusters
$clusters = Get-Cluster
# Loop through each cluster
$result = foreach ($cluster in $clusters) {
# Use calculated properties to create custom object
Get-VM -Location $cluster | Select @{n='Cluster';e={$cluster.Name}},@{n='VM Name';e={$_.Name}}
}
I have several clusters. Each cluster has several nodes which host a number of VMs.
I have tried to get all clusters that exist within the domain with this code , but it give me an error.
This is the code:
get-cluster
This is the error:
WARNING: If you are running Windows PowerShell remotely, note that some failover clustering cmdlets
do not work remotely. When possible, run the cmdlet locally and specify a remote computer as the tar
get. To run the cmdlet remotely, try using the Credential Security Service Provider (CredSSP). All a
dditional errors or warnings from this cmdlet might be caused by running it remotely.
Get-Cluster : The cluster service is not running. Make sure that the service is running on all
nodes in the cluster.
There are no more endpoints available from the endpoint mapper
At line:1 char:1
+ Get-Cluster
However, after adding an " * " to " get-cluster" , I get the list of all clusters available on the network
get-cluster *
This is the result:
Name
----
HOst1
HOst2
HOst3
HOst4
HOst5
I tried to use this code to get all the VMs available within the Network with the " * " next to get-cluster but I got an error:
Code:
Error:
Get-VM : The cluster object 'Host1' is not a valid cluster group or virtual machine
cluster resource. Run the command again and specify an object that represents a cluster group or
virtual machine cluster resource.
At line:1 char:2
+ Get-VM $cluster
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-VM], VirtualizationException
+ FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.GetVM
Can anyone help me please. Is it a problem of permissions? do I need to run the scrip on every single host within the cluster remotely to get all vm they run?
Please do not hijack other peoples threads. If you have a question on the same topic you should create a new thread for yourself and add a link to the post you’re refering to to your question.