When I run the command below...
Get-Cluster yomama | Get-Datastore | Sort-Object -Property FreeSpaceGB -Descending | Format-Table -HideTableHeaders
The output is truncated then appended with a "…"
esx-somebody-made-long-name...
The actual name is
esx-somebody-made-long-name-for-the-hell-of-it
Looks like if more than 29 or 30 characters it does this.
What's the command to output the full name?
Thanks
Btw, you can reset that default behaviour by using the Out-Default cmdlet.
For example
Get-Datastore -Name esx* | Sort-Object -Property FreeSpaceGB -Descending | Select @{N = 'Name'; E = {"{0}" -f $_.Name}}, FreeSpaceGB, CapacityGB
will produce
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I don't see that behavior. What if you:
$a = get-datacenter yomama | get-cluster "jomama" | get-datastore
then
$a.Name
Does it do it then?
My fault, I pasted in the incorrect commands.
See updated post.
The real explanation is that the PowerCLI cmdlets use Extended Data Types to display properties from PowerCLI objects.
These data types are defined in the .ps1xml files that live in the PowerCLI modules.
In this case the Name property of a Datastore object is limited to 30 characters.
And 30 minus the three dots makes 27.
This is the part of the VMware.VimAutomation.Format.ps1xml file where that is defined.
In fact this was one of the subjects we handled in out VMworld session VIN1992BU (US) and VIN1992BE (Europe).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
To get the full name you can use the format operator (-f).
Like this
Select @{N='Name';E={"{0}" -f $_.Name}},FreeSpaceGB,CapacityGB
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I modified my ps1 scripts and ran it in my .Net VB Windows Forms app and it worked like a charm!
EDIT:
I was wrong, the FreeSpaceGB and CapacityGB did not come over.
Marked thread unanswered.
If you don't see that behaviour, then you are not looking correctly, unless you overwrote the default .ps1xml files that come with PowerCLI
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD, I used your command like below with the cluster name....
Get-Cluster jomama | Get-Datastore | Sort-Object -Property FreeSpaceGB -Descending | Select @{N='Name';E={"{0}" -f $_.Name}},FreeSpaceGB,CapacityGB
But the output formatted like this....
Name : vmware-sql-logs-test-t1-nfs02
FreeSpaceGB : 99.10546875
CapacityGB : 100
Name : vmware-sql-logdir-test-t1-nfs02
FreeSpaceGB : 98.2705078125
CapacityGB : 100
PowerShell normally uses a list, instead of a table, when there are 5 or more properties to show.
I have no clue why you get that behaviour with only 3 properties.
Where are you running that code?
In VSC, ISE or from a PS prompt?
What does $host.UI.RawUI.BufferSize show?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here's the weird part.....
When I run the command below in a plain single command in a PowerCLI window, the output format is correct.
Get-Cluster cos_wan2 | Get-Datastore | Sort-Object -Property FreeSpaceGB -Descending | Select @{N='Name';E={"{0}" -f $_.Name}},FreeSpaceGB,CapacityGB
Name FreeSpaceGB CapacityGB
---- ----------- ----------
vmware-sql-sysdb-test-t1-nfs02 99.140625 100
vmware-sql-logs-test-t1-nfs02 99.10546875 100
But when I run the command from within a .ps1 file, that's when it gives me the output like below....
Name : vmware-sql-sysdb-test-t1-nfs02
FreeSpaceGB : 99.140625
CapacityGB : 100
Name : vmware-sql-logs-test-t1-nfs02
FreeSpaceGB : 99.10546875
CapacityGB : 100
Any ideas?
I don't get that issue either. Without seeing how you're executing it and where the output is going, it's difficult for me (personally, because I have a large imagination for all kinds of stuff you could be doing) to understand your issue.
If I open a PowerCLI command prompt window and run your command, I get the formatted table. If I cd to the directory of the same command in a .ps1 file and execute via ./filename.ps1 then it still works the same way for me.
Care to give more info?
What does $host.UI.RawUI.BufferSize say?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You mention "PowerCLI window", which PowerCLI version are you using?
Recent PowerCLI version don't have a PowerCLI window anymore.
Are you using a shortcut from an older PowerCLI version?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PowerCLI window is just a PS command window with import-module VMware.PowerCLI. I still use it for VMware-specific stuff because I have a command window configured to auto-load the module and connect to a VI server, just saves time.
I am curious-- I'm not sure what "Recent PowerCLI version don't have a PowerCLI window anymore" means... so what does it have?... just a standard PS command window and you manually load the module, or something else? Educate me.
I use whatever the default install of 6.5 created on my desktops shortcut...
Shortcut points to below....
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noe -c ". \"C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\" $true"
Here's the output of the windows...
Output when executed from a .ps1 file...
Ok, so you are still using a version with PSSnapin.
Up until 6.5 R1 when you installed PowerCLI it also installed a shortcut on your desktop.
That shortcut pointed to an init script that did load the PSSnapin and modules, and configured a PowerShell prompt, where it for example changed the Window title.
Post PowerCLI 6.5 R1, there is no more MSI file, all modules (no more PSSnapin) are installed from the PSGallery.
See Welcome PowerCLI to the PowerShell Gallery – Install Process Updates
Since PowerShell v4, you also don't have to explicitly import the PowerCLI modules anymore.
That is done through the PowerShell module autoload feature.
The 1st time you use a cmdlet from a module, PS will autoload that module for you.
In your .ps1 script I see some pre-amble, including manipulation of the console window.
What else is done in those preceding lines?
From where did you get those lines?
Are those a copy of the old init script I mentioned?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
"What else is done in those preceding lines?"
Here's the entire contents of my script....
param([bool]$promptForCEIP = $false)
# List of modules to be loaded
$moduleList = @(
"VMware.VimAutomation.Core",
"VMware.VimAutomation.Vds",
"VMware.VimAutomation.Cloud",
"VMware.VimAutomation.PCloud",
"VMware.VimAutomation.Cis.Core",
"VMware.VimAutomation.Storage",
"VMware.VimAutomation.HorizonView",
"VMware.VimAutomation.HA",
"VMware.VimAutomation.vROps",
"VMware.VumAutomation",
"VMware.DeployAutomation",
"VMware.ImageBuilder",
"VMware.VimAutomation.License"
)
$productName = "PowerCLI"
$productShortName = "PowerCLI"
$loadingActivity = "Loading $productName"
$script:completedActivities = 0
$script:percentComplete = 0
$script:currentActivity = ""
$script:totalActivities = `
$moduleList.Count + 1
function ReportStartOfActivity($activity) {
$script:currentActivity = $activity
Write-Progress -Activity $loadingActivity -CurrentOperation $script:currentActivity -PercentComplete $script:percentComplete
}
function ReportFinishedActivity() {
$script:completedActivities++
$script:percentComplete = (100.0 / $totalActivities) * $script:completedActivities
$script:percentComplete = [Math]::Min(99, $percentComplete)
Write-Progress -Activity $loadingActivity -CurrentOperation $script:currentActivity -PercentComplete $script:percentComplete
}
# Load modules
function LoadModules(){
ReportStartOfActivity "Searching for $productShortName module components..."
$loaded = Get-Module -Name $moduleList -ErrorAction Ignore | % {$_.Name}
$registered = Get-Module -Name $moduleList -ListAvailable -ErrorAction Ignore | % {$_.Name}
$notLoaded = $registered | ? {$loaded -notcontains $_}
ReportFinishedActivity
foreach ($module in $registered) {
if ($loaded -notcontains $module) {
ReportStartOfActivity "Loading module $module"
Import-Module $module
ReportFinishedActivity
}
}
}
LoadModules
# Update PowerCLI version after snap-in load
$powerCliFriendlyVersion = [VMware.VimAutomation.Sdk.Util10.ProductInfo]::PowerCLIFriendlyVersion
$host.ui.RawUI.WindowTitle = $powerCliFriendlyVersion
#write-host ""
Connect-VIServer -Server "MYSERVERNAME"
Get-Cluster JOMAMA | Get-Datastore | Sort-Object -Property FreeSpaceGB -Descending | Select @{N='Name';E={"{0}" -f $_.Name}},FreeSpaceGB,CapacityGB
Disconnect-VIServer -Server "MYSERVERNAME" -Confir:$false
"From where did you get those lines?"
From the shortcut pointer on my desktop that called the file "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1". I grabbed the beginning portion that loaded the modules and it allowed me to run all the PowerCLI commands.
"Are those a copy of the old init script I mentioned?"
Maybe? (◔/‿\◔)
Thanks
"What does $host.UI.RawUI.BufferSize show?"
It returns this...
PowerCLI C:\Temp> $host.UI.RawUI.BufferSize
Width Height
----- ------
170 0
Just open the regular PowerShell ISE, try this:
Import-Module -Name VMware.PowerCLI
Connect-VIServer -Server "MYSERVERNAME"
Get-Cluster JOMAMA | Get-Datastore | Sort-Object -Property FreeSpaceGB -Descending | Select @{N='Name';E={"{0}" -f $_.Name}},FreeSpaceGB,CapacityGB
At least it will rule out a) whether it's any of the VMware stuff overlayed onto ISE, and b) anything in your code. It formats correctly in my PS ISE, but I'm not running any of the VMware stuff overlayed.
Yes, they are (a copy of the init script).
But I think I might have an answer to what you are seeing.
In a script, when the first output to the console ends up as a list vs a table (the 5 or more properties rule).
All subsequent output in that script will also be presented in the list format.
For example when I add a line before the line with the 3 properties
Get-Datastore -Name esx* | Sort-Object -Property FreeSpaceGB -Descending | Select @{N = 'Name'; E = {"{0}" -f $_.Name}}, FreeSpaceGB, CapacityGB
And now execute this as a .ps1 file, I get
The 1st line is presented as a list due to the 5 properties.
And from there on, every output is presented as a list (even when less than 5 properties).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference