Powercli List Provision space of all datastores in a cluster

compdigit44
compdigit44 used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Luciano PatrãoICT Senior Infraestructure  Engineer  

Commented:
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

Author

Commented:
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ãoICT Senior Infraestructure  Engineer  

Commented:
Hi,

Are you copy the full script like it is? Because I don't get any error when I run that script.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Yes I did, Also I tried it will already authentication to vcenter in powercli and letting the script do it.. Same result
Luciano PatrãoICT Senior Infraestructure  Engineer  

Commented:
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

Author

Commented:
I copied and pasted everything from you using posted and tried in in PowerCLi and Windows Powershell ISE both getting the same error.
Luciano PatrãoICT Senior Infraestructure  Engineer  

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

Witch version of PowerCli do you have?
Luciano PatrãoICT Senior Infraestructure  Engineer  

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

Author

Commented:
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
Luciano PatrãoICT Senior Infraestructure  Engineer  

Commented:
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

Author

Commented:
Sorry, but the script file contains only contains what you posted earlier. I did not edit anything
Luciano PatrãoICT Senior Infraestructure  Engineer  

Commented:
When I say sensitive information, is like user/password, IP addresses of vCenter etc. Then upload here that file script.

Author

Commented:
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ãoICT Senior Infraestructure  Engineer  

Commented:
Hi

But did you manage to put the script to work?

Author

Commented:
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

Luciano PatrãoICT Senior Infraestructure  Engineer  

Commented:
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.

Author

Commented:
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ãoICT Senior Infraestructure  Engineer  

Commented:
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

Author

Commented:
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ãoICT Senior Infraestructure  Engineer  

Commented:
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.

Author

Commented:
same error and need to go through the script in detail again.
ICT Senior Infraestructure  Engineer  
Commented:
Aff :(

Do you have a PowerShell/CLI editor like PowerGUI Editor? If not, can you download and use it and run the script from there?

Did you try to test this in a different computer?

By the way, what is your PowerShell version?

Just to make sure, I switch computer (from my home lab) , to my company computer and run the script against one of the Production vCenter, and again works.

This is the versions that I have in the company computer:

#### PowerCLI 
PowerCLI C:\> Get-PowerCLIVersion
 
PowerCLI Version
----------------
   VMware vSphere PowerCLI 6.3 Release 1 build 3737840
---------------
Component Versions
---------------
   VMware Cloud Infrastructure Suite PowerCLI Component 6.3 build 3709081
   VMWare AutoDeploy PowerCLI Component 6.0 build 3736841
   VMWare ImageBuilder PowerCLI Component 6.0 build 3736841
   VMware vSphere PowerCLI Component 6.3 build 3709081
   VMware VDS PowerCLI Component 6.3 build 3709081
   VMware vCloud Director PowerCLI Component 6.3 build 3615264
   VMware HA PowerCLI Component 6.0 build 3625284
   VMware License PowerCLI Component 6.0 build 3615733
   VMware vCloud Air PowerCLI Component 6.3 build 3615264
   VMware PowerCLI Component for Storage Management 6.0 build 3617867
   VMware vROps PowerCLI Component 6.3 build 3615304
   VMware vSphere Update Manager PowerCLI 6.1 build 3607502
 
#### PowerShell
PS C:\windows\system32> Get-Host
 
 
Name             : ConsoleHost
Version          : 5.0.10586.117
InstanceId       : 343ed555-19fe-4f62-84e5-7d8caf79e013
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Open in new window


Honestly I am getting out of options :)

Author

Commented:
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ãoICT Senior Infraestructure  Engineer  

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

Have you try in a different computer??

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial