I have a vcenter server called ThreeStooges.
In that vcenter there are 3 datacenters called Larry, Curly and Moe.
Each datacenter has a cluster and of course they all have datastores.
How can I get a list of all the datacenters with their clusters and datastores in a tab separated value (TSV) like below....
vcenter | datacenter | cluster | datastore |
ThreeStooges | Larry | Klust01_lry | nfs_lry |
ThreeStooges | Larry | Klust02_lry | iscsi_lry |
ThreeStooges | Moe | Klust01_moe | sata_moe |
ThreeStooges | Moe | Klust02_moe | sas_moe |
ThreeStooges | Curly | Klust01_cur | ssd_cur |
ThreeStooges | Curly | Klust02_cur | nvme_cur |
Thanks
Try something like this
Get-Datacenter -PipelineVariable dc |
Get-Cluster -PipelineVariable cluster |
Get-Datastore |
Select @{N='vCenter';E={([uri]$_.ExtensionData.Client.ServiceUrl).Host}},
@{N='Datacenter';E={$dc.Name}},
@{N='Cluster';E={$cluster.Name}},
@{N='Datastore';E={$_.Name}} |
Export-Csv -Path .\report.csv -Delimiter "`t"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK, I ran into an error with the out file to TSV so I removed it just to see if it runs.
It started to get me data below.....
vCenter Datacenter Cluster Datastore
------- ---------- ------- ---------
ThreeStooges Curly Klust01_cur FlyBy-Night02-TB-NFS01-STD-600G
ThreeStooges Curly Klust01_cur FlyBy-Night01-TB-Hard
ThreeStooges Curly Klust01_cur FlyBy-Night02-TB-Hard-2
ThreeStooges Curly Klust01_cur datastore1 (3)
ThreeStooges Curly Klust01_cur FlyBy-Night01-TB-DEV-NFS1
ThreeStooges Curly Klust01_cur FlyBy-Night01-TA-Hard-2
ThreeStooges Curly Klust01_cur FlyBy-Night02-TA-NFS02-STD-600G
ThreeStooges Curly Klust01_cur FlyBy-Night01-TA-Hard
ThreeStooges Curly Klust02_cur datastore1 (5)
ThreeStooges Curly Klust02_cur datastore1 (4)
ThreeStooges Curly Klust02_cur datastore1 (1)
ThreeStooges Curly Klust02_cur datastore1 (2)
ThreeStooges Curly Klust02_cur datastore1 (7)
ThreeStooges Curly Klust02_cur datastore1 (6)
ThreeStooges Curly Klust02_cur datastore1
But then right after I get this in all red text.....
Get-Cluster : 12/3/2018 1:16:02 PM Get-Cluster VMHost parameter: Could not find any of the objects specified by name.
At line:1 char:39
+ ... -PipelineVariable dc | Get-Cluster -PipelineVariable cluster | Get-D ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (VMware.VimAutom...VMHost[] VMHost:RuntimePropertyInfo) [Get-Cluster], ObnRecordProcessingFailedException
+ FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetCluster
Get-Cluster : 12/3/2018 1:16:02 PM Get-Cluster VMHost parameter: Could not find any of the objects specified by name.
At line:1 char:39
+ ... -PipelineVariable dc | Get-Cluster -PipelineVariable cluster | Get-D ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (VMware.VimAutom...VMHost[] VMHost:RuntimePropertyInfo) [Get-Cluster], ObnRecordProcessingFailedException
+ FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetCluster
Get-Cluster : 12/3/2018 1:16:02 PM Get-Cluster VMHost parameter: Could not find any of the objects specified by name.
At line:1 char:39
+ ... -PipelineVariable dc | Get-Cluster -PipelineVariable cluster | Get-D ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (VMware.VimAutom...VMHost[] VMHost:RuntimePropertyInfo) [Get-Cluster], ObnRecordProcessingFailedException
+ FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetCluster
Get-Cluster : 12/3/2018 1:16:02 PM Get-Cluster VMHost parameter: Could not find any of the objects specified by name.
At line:1 char:39
+ ... -PipelineVariable dc | Get-Cluster -PipelineVariable cluster | Get-D ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (VMware.VimAutom...VMHost[] VMHost:RuntimePropertyInfo) [Get-Cluster], ObnRecordProcessingFailedException
+ FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetCluster
Thanks
Which PowerShell (check with $PSVersionTable) and which PowerCLI version are you running.
For PowerCLI do a
Get-Module -Name VMware* -ListAvailable
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here's the output.....
Directory: C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Binary 6.0.0.0 VMware.DeployAutomation
Binary 6.0.0.0 VMware.ImageBuilder
Binary 6.5.0.4... VMware.VimAutomation.Cis.Core
Binary 6.5.0.4... VMware.VimAutomation.Cloud
Manifest 6.5.0.4... VMware.VimAutomation.Common
Binary 6.5.0.2... VMware.VimAutomation.Core HookGetViewAutoCompleter
Binary 6.0.0.0 VMware.VimAutomation.HA
Binary 7.0.2.4... VMware.VimAutomation.HorizonView
Binary 6.5.0.4... VMware.VimAutomation.License
Binary 6.5.0.4... VMware.VimAutomation.PCloud
Manifest 6.5.0.4... VMware.VimAutomation.Sdk Get-PSVersion
Binary 6.5.0.4... VMware.VimAutomation.Storage
Binary 6.5.0.4... VMware.VimAutomation.Vds
Binary 6.5.0.4... VMware.VimAutomation.vROps
Binary 6.0.0.0 VMware.VumAutomation
Oh my, that is a quite old PowerCLI version.
And what PowerShell version are you using?
What does $PSVersionTable show?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If you are using an older PowerShell version, you might want to try this version.
$report = foreach($dc in Get-Datacenter){
foreach($cluster in Get-Cluster -Location $dc){
Get-Datastore -RelatedObject $cluster |
Select @{N='vCenter';E={([uri]$_.ExtensionData.Client.ServiceUrl).Host}},
@{N='Datacenter';E={$dc.Name}},
@{N='Cluster';E={$cluster.Name}},
@{N='Datastore';E={$_.Name}}
}
}
$report | Export-Csv -Path .\report.csv -Delimiter "`t"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here's the $PSVersionTable results...
Name Value
---- -----
PSVersion 5.1.14393.1944
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1944
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Can you post me a link to the latest version of PowerCLI for download?
Thanks
There are no download links anymore, the PowerCLI modules are now available from the PowerShell Gallery.
See Welcome PowerCLI to the PowerShell Gallery – Install Process Updates for the updated installation procedures.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Uh oh, well that broke my powercli.
Ran the command "Install-Module -Name VMware.PowerCLI –Scope AllUsers" and now it repeatedly prompts me for credentials. When I plug in my credentials it never connects.
lol
When you use Scope AllUser you need to provide administrator credentials.
You can also use Scope CurrentUser, then it should work with your current user, and will not prompt for credentials.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK, I'll give that a try in a bit. I had to restore from backup yesterday.
The goal is to get it to work for all users as this is a team terminal server.
Thanks
OK, I ran the commands an here's the output result after install...…
Log in to a vCenter Server or ESX host: Connect-VIServer
To find out what commands are available, type: Get-VICommand
To show searchable help for all PowerCLI commands: Get-PowerCLIHelp
Once you've connected, display all virtual machines: Get-VM
If you need more help, visit the PowerCLI community: Get-PowerCLICommunity
Copyright (C) VMware, Inc. All rights reserved.
PowerCLI C:\> Find-Module -Name VMware.PowerCLI
NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files
(x86)\PackageManagement\ProviderAssemblies' or 'C:\Users\PAM-LaoyanG\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running
'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
Version Name Repository Description
------- ---- ---------- -----------
11.0.0.... VMware.PowerCLI PSGallery This Windows PowerShell module contains VMware.PowerCLI
PowerCLI C:\> Install-Module -Name VMware.PowerCLI -Scope CurrentUser
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you
sure you want to install the modules from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A
PackageManagement\Install-Package : A command with name 'Export-VM' is already available on this system. This module 'VMware.VimAutomation.Core' may override the existing
commands. If you still want to install this module 'VMware.VimAutomation.Core', use -AllowClobber parameter.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ... $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
+ FullyQualifiedErrorId : CommandAlreadyAvailable,Validate-ModuleCommandAlreadyAvailable,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
PowerCLI C:\>
But I still get prompted for credentials.....
Any ideas?
Thanks