• This topic has 1 reply, 2 voices, and was last updated October 21, 2019 by Brandon S.

PowerCLI Properties

  • Is there a workable equivalent of this that will allow me to dig deeper in powercli ?

    foreach ($site in Get-Sites 10.10.10.10 9080 administrator password)
    {
    Write-Host $site | Select-Object -Property *
    }

    I would work up something like this

    #Connect to ZVM
    Connect-ZertoZVM
    #create empty array to dump my final product
    $refinedresults = @()
    
    #save all sites to a variable
    $mysites = Get-ZertoSite
    
    #enumerate through each site and do what you need to.
    foreach ( $site in $mysites )
    {
    #add a custom property to my site such as a friendly name value or a scripted property or something
    $site | Add-Member -NotePropertyName 'MyCustomProperty' -NotePropertyValue {'do stuff here'}
    
    #check for a certain condition to help filter my results
    if ( $site.property -ne 'value' ) {
    Write-Host 'Some response'
    
    } else {
    #add my result to the final
    $refinedresults += $site
    }
    
    }

    I’d recommend not writing to host unless you absolutely have to. Once you refined your results, you could do something like this:

    
    $refinedresults | select 'property1','property2','property3','property4'
    

    the important thing to remember is to use variables. That will let you work with the object as much as you want before you output the final result.

You must be logged in to create new topics. Click here to login