Hi,
I have list datastores Name, I need to get the respective hosts cluster name in powercli. Please help me.
Thanks
You didn't specify in which format that "list datastores Name" is provided, but when I assume it is a CSV with a column named DSName, you could do
Import-Csv -Path .\datastores.csv -UseCulture |
Foreach-Object -Process {
Get-Datastore -Name $_.DSName |
Select Name,
@{N='Cluster';E={(Get-VMHost -Datastore $_ | Get-Cluster).Name}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perhaps you could use the code I give and not change it?
Import-Csv -Path .\datastores.csv -UseCulture |
Foreach-Object -Process {
Get-Datastore -Name $_.DSName |
Select Name,
@{N='Cluster';E={(Get-VMHost -Datastore $_ | Get-Cluster).Name}}
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You didn't specify in which format that "list datastores Name" is provided, but when I assume it is a CSV with a column named DSName, you could do
Import-Csv -Path .\datastores.csv -UseCulture |
Foreach-Object -Process {
Get-Datastore -Name $_.DSName |
Select Name,
@{N='Cluster';E={(Get-VMHost -Datastore $_ | Get-Cluster).Name}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Getting error as attached.
Where is that Disconnect-VIServer coming from?
That was not in the code I posted.
The code assumes you are connected to the vCenter.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Disconnect-VIServer is added my self. Script is working now. But, When I try to export data in CSV, getting cluster detail for only one datastore only. otherwise on screen output shows for all datastore.
That probably means you placed the Export-Csv inside the Forwach-Object loop, hence overwriting the CSV each time.
You have to place the Export-Csv outside the Foreach-Object code block
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Now, I have kept my Export-CSV in out of foreach, but still I am getting cluster detail only for last datastore in the list.
Can you show the code you are using?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Unable to copy and paste the code here due to limited access, just providing the screenshot of the code.
You are overwriting the variable $p inside the loop each time.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
How can I stop overwriting $p in the script.
Perhaps you could use the code I give and not change it?
Import-Csv -Path .\datastores.csv -UseCulture |
Foreach-Object -Process {
Get-Datastore -Name $_.DSName |
Select Name,
@{N='Cluster';E={(Get-VMHost -Datastore $_ | Get-Cluster).Name}}
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
I tried with your code and getting below error.
I found the issue and fixed it..
It works now..
Thank you LucD