PowerCLI

 View Only
Expand all | Collapse all

long datastore names truncated after Get-Datastore

  • 1.  long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 09:56 PM

    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



  • 2.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 10:01 PM

    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?



  • 3.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 10:08 PM

    My fault, I pasted in the incorrect commands.

    See updated post.



  • 4.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 10:29 PM

    To get the full name you can use the format operator (-f).

    Like this

    Get-Datastore -Name esx* | Sort-Object -Property FreeSpaceGB -Descending  |

    Select @{N='Name';E={"{0}" -f $_.Name}},FreeSpaceGB,CapacityGB



  • 5.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 10:42 PM

    @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



  • 6.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 10:48 PM

    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?



  • 7.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 10:59 PM

    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?



  • 8.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 11:06 PM

    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?



  • 9.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 11:11 PM

    What does $host.UI.RawUI.BufferSize say?



  • 10.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 11:13 PM

    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?



  • 11.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 11:22 PM

    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.



  • 12.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 11:27 PM

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



  • 13.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 11:35 PM

    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?



  • 14.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 11:52 PM

    "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



  • 15.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 10, 2018 12:02 AM

    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* | Select Name, FreeSpaceMB, FreespaceGB, CapacityMB, CapacityGB

    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).



  • 16.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 10, 2018 12:01 AM

    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.



  • 17.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 10, 2018 12:08 AM

    I had high hopes for this one but I got this....



  • 18.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 10, 2018 12:11 AM

    There is no VMware.PowerCLI module in 6.5 R1, that only appeared in 6.5.1 (which is not the same as 6.5 R1)



  • 19.  RE: long datastore names truncated after Get-Datastore
    Best Answer

    Posted Nov 10, 2018 12:08 AM

    Btw, you can reset that default behaviour by using the Out-Default cmdlet.

    For example

    Get-Datastore -Name esx* | Select Name, FreeSpaceMB, FreespaceGB, CapacityMB, CapacityGB | Out-Default

    Get-Datastore -Name esx* | Sort-Object -Property FreeSpaceGB -Descending | Select @{N = 'Name'; E = {"{0}" -f $_.Name}}, FreeSpaceGB, CapacityGB

    will produce



  • 20.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 10, 2018 12:11 AM

    Yep, sorry mate-- I guess we're running different versions of vSphere and the PowerCLI.

    This is craziness, LucD… good find.

    He can fix it by adding a simple pipe at the end:

    | Format-Table

    And it will make it a table again.

    Get-Datastore -Name esx* | Select Name, FreeSpaceMB, FreespaceGB, CapacityMB, CapacityGB

    Get-Datastore -Name esx* | Sort-Object -Property FreeSpaceGB -Descending | Select @{N = 'Name'; E = {"{0}" -f $_.Name}}, FreeSpaceGB, CapacityGB | Format-Table



  • 21.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 10, 2018 12:20 AM

    Adding " | Out-Default" to the end fixed it across all execution methods including from within my VB .Net App.

    Thanks again!!!



  • 22.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 10, 2018 12:24 AM

    Yes, it's like writing HTML for different browsers... you think it's perfect and somebody opens up your webpage in Opera or old IE 7 and suddenly it looks like trash.  Dealing with different execution methods can be quite a headache... yes, that was a strange issue and a good find by LucD that with 5 properties it would change how it would format subsequent output... strange.  Glad it's fixed!



  • 23.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 11:55 PM

    "What does $host.UI.RawUI.BufferSize show?"

    It returns this...

    PowerCLI C:\Temp>  $host.UI.RawUI.BufferSize

    Width Height
    ----- ------
      170      0



  • 24.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 10:29 PM

    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.



  • 25.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 10:29 PM

    If you don't see that behaviour, then you are not looking correctly, unless you overwrote the default .ps1xml files that come with PowerCLI



  • 26.  RE: long datastore names truncated after Get-Datastore

    Posted Nov 09, 2018 10:20 PM

    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).