Avatar of compdigit44
compdigit44
 asked on

Powercli List Provision space of all datastores in a cluster

I am trying to use PowerCli to list all datastores assoicated with a cluster then list the datastores capacity, amount of free space and "provisioned spaced". From what I have read I many need to use the get-view command with I have not used before. I am not strong in powercli so looking for some guidance on this.
VMware* PowerCLI

Avatar of undefined
Last Comment
Luciano Patrão

8/22/2022 - Mon
Luciano Patrão

Hi,

Here is a script that provide you that information.

$server = "IP/vCenter Name"
$user = "vCenter user"
$pwd = "vCenter user pass" 

Connect-VIServer $server -User $user -Password $pwd
cls

$datastores = get-datastore | get-view
$datastores | select -expandproperty summary | select name, @{N=”Capacity (GB)”; E={[math]::round($_.Capacity/1GB,2)}}, 
@{N=”FreeSpace (GB)”;E={[math]::round($_.FreeSpace/1GB,2)}}, @{N=”Provisioned (GB)”; E={[math]::round(($_.Capacity – $_.FreeSpace + $_.Uncommitted)/1GB,2) }}| sort -Property Name | Export-Csv 'path\datastores.csv'  -NoTypeInformation

Disconnect-VIServer $server -Confirm:$false

Open in new window


Hope this can help

Jail
compdigit44

ASKER
Thanks again, I ran the script an getting the following error:


+ ... nd(($_.Capacity â?" $_.FreeSpace + $_.Uncommitted)/1GB,2) }}| sort
-Property Nam ...
+                    ~
Missing ')' in method call.
Luciano Patrão

Hi,

Are you copy the full script like it is? Because I don't get any error when I run that script.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
compdigit44

ASKER
Yes I did, Also I tried it will already authentication to vcenter in powercli and letting the script do it.. Same result
Luciano Patrão

Hi,

where are you running the script? Are you using a tool like PowerCli Script Editor? Or are you just copy into PowerCli shell console?

If you are using an Editor you can run the script as is, but if you are copy past to the shell console, you need to be aware that line 9 and 10 is just one line, not 2. So you need to copy the full line like this:

$datastores | select -expandproperty summary | select name, @{N=”Capacity (GB)”; E={[math]::round($_.Capacity/1GB,2)}}, @{N=”FreeSpace (GB)”;E={[math]::round($_.FreeSpace/1GB,2)}}, @{N=”Provisioned (GB)”; E={[math]::round(($_.Capacity – $_.FreeSpace + $_.Uncommitted)/1GB,2) }}| sort -Property Name | Export-Csv 'path\datastores.csv'  -NoTypeInformation

Also you are changing the part 'path\datastores.csv' ?? To add your path to save the file? Something like 'c:\scripts\datastores.csv'

I tested again with a script editor and in PowerCli shell it works perfectly.

Jail
compdigit44

ASKER
I copied and pasted everything from you using posted and tried in in PowerCLi and Windows Powershell ISE both getting the same error.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Luciano Patrão

This is VMware so this needs to be used in PowerCLI, not Powershell

Witch version of PowerCli do you have?
Luciano Patrão

Please tried again, then take a printscreen of the shell console with all the steps and upload here please.
compdigit44

ASKER
I am sorry for the confusion. I know Vmware commandlets  can only be run in Powercli and only tried them in the regular Windows Powershell after importing the Powercli snap-in. I am using Powercli version 6.3 Release 1 and have attached the screen shot as requested. Also I have copied and pasted everything you listed and made sure no extra space or returns are present
PowerCliErrors.png
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Luciano Patrão

Hi

That doesn't show me anything, because you are using a script file. I was talking running the script/commands directly in the console.

Remove any sensitive information from that file, and upload the file here. I will check and run in my side
compdigit44

ASKER
Sorry, but the script file contains only contains what you posted earlier. I did not edit anything
Luciano Patrão

When I say sensitive information, is like user/password, IP addresses of vCenter etc. Then upload here that file script.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
compdigit44

ASKER
I am sorry for the delay in getting back to you. I was out of the office sick and catching up on items and will look at this tomorrow. Thank you so much for you help as always. I am sure this is 100% user error on my part.
Luciano Patrão

Hi

But did you manage to put the script to work?
compdigit44

ASKER
So for the late reply... Below is what I have in the body of the script which errors out with the same errors I posted before

$server = "vcenter.domain.com"
$user = "domain\user1"
$pwd = "mypwd" 

Connect-VIServer $server -User $user -Password $pwd
cls

$datastores = get-datastore | get-view
$datastores | select -expandproperty summary | select name, @{N=”Capacity (GB)”; E={[math]::round($_.Capacity/1GB,2)}}, 
@{N=”FreeSpace (GB)”;E={[math]::round($_.FreeSpace/1GB,2)}}, @{N=”Provisioned (GB)”; E={[math]::round(($_.Capacity – $_.FreeSpace + $_.Uncommitted)/1GB,2) }}| sort -Property Name | Export-Csv 'path\datastores.csv'  -NoTypeInformation

Disconnect-VIServer $server -Confirm:$false

Open in new window

Your help has saved me hundreds of hours of internet surfing.
fblack61
Luciano Patrão

Hi,

The script like that have an error.

Like I said you need to change the path for where you want the report be saved.

You have: Export-Csv 'path\datastores.csv'  -NoTypeInformation

When should have something similar like this: Export-Csv 'c:\temp\datastores.csv'  -NoTypeInformation

The path you should add where you want save the file.

When I change that, it runs without any error.
compdigit44

ASKER
I did update the CSV file location by failed to add that in when i uploaded the information. MY mistake, regardless when I run the script with the information above and the CSV location to C:\Exports.csv I get the error below.. Yet I have copied exactily what you posted

char:96
+ ... ned (GB)â??; E={[math]::round(($_.Capacity â?" $_.FreeSpace +
$_.Uncommitted)/1G ...
+                    ~
Missing closing '}' in statement block.
Luciano Patrão

You cannot put directly to the c:\, you need to add to a folder.

But when we save directly to the drive the error should be different. Like this: Export-Csv : Access to the path 'C:\datastores.csv' is denied.

Test with a folder please.

But that "Missing closing '}' in statement block" is killing me.

What version Powercli do you have? The only option is the PowerCLI version

This mine...

PowerCLI C:\> Get-PowerCLIVersion

PowerCLI Version
----------------
   VMware PowerCLI 6.5 Release 1 build 4624819
---------------
Component Versions
---------------
   VMware Cis Core PowerCLI Component 6.5 build 4624453
   VMware VimAutomation Core PowerCLI Component 6.5 build 4624450
   VMWare ImageBuilder PowerCLI Component 6.5 build 4561891
   VMWare AutoDeploy PowerCLI Component 6.5 build 4561891
   VMware Vds PowerCLI Component 6.5 build 4624695
   VMware Cloud PowerCLI Component 6.5 build 4624821
   VMware HA PowerCLI Component 6.0 build 4525225
   VMware HorizonView PowerCLI Component 7.0.2 build 4596620
   VMware Licensing PowerCLI Component 6.5 build 4624822
   VMware PCloud PowerCLI Component 6.5 build 4624825
   VMware Storage PowerCLI Component 6.5 build 4624820
   VMware vROps PowerCLI Component 6.5 build 4624824
   VMware vSphere Update Manager PowerCLI 6.5 build 4540462

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
compdigit44

ASKER
I am using the same build of Powercli as you. The problem is it keeps saying a bracket is missing yet I have got line by line can do not see one missing
Luciano Patrão

Ok I may found the problem in your copy/past script. Not sure, but I have seen this before.

Because when we copy/past sometimes the quote get changed.

So all quote should be  " " and not  “ ”
 
Can you double check the script if is the write quotes? Because I see here some strange characters + ... ned (GB)â??; E={[math]::round(($_.Capacity â?" $_.FreeSpace +

To bypass this issue, I change the " to '

Connect-VIServer $server -User $user -Password $pwd
cls

$datastores = get-datastore | get-view
$datastores | select -expandproperty summary | select name, @{N='Capacity (GB)'; E={[math]::round($_.Capacity/1GB,2)}}, 
@{N='FreeSpace (GB)';E={[math]::round($_.FreeSpace/1GB,2)}}, @{N='Provisioned (GB)'; E={[math]::round(($_.Capacity – $_.FreeSpace + $_.Uncommitted)/1GB,2) }}| sort -Property Name | Export-Csv 'C:\app\datastores.csv'  -NoTypeInformation

Disconnect-VIServer $server -Confirm:$false

Open in new window


Run again and let me know.
compdigit44

ASKER
same error and need to go through the script in detail again.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Luciano Patrão

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
compdigit44

ASKER
I was never able to get this to work, check all of my syntax which I copied and pasted directly multiple times and not luck. I you have great helping me with this and wanted to give you the points for all of your efforts...
Luciano Patrão

Sorry that you weren't able to put the script to work.

Have you try in a different computer??