1

I have a list of object $Results which contains different columns every time we run the script according to user input but one column is fixed every time called ItemID

I am trying to display all columns present in $Results except ItemID using Show-ListView but I am not able to find any command for this

1 Answer 1

1

You can prepare a custom object and include the required property in the custom object. That way you can exclude other properties.

$item = Get-Item -Path "master:\content\home\sample item 1"
 
$Results = [pscustomobject]@{
    "Icon"=$Item.__Icon
    "DisplayName"=$Item.DisplayName
    "ItemPath"=$Item.ItemPath
    "Version"=$Item.Version
    "Language"=$Item.Language
}

$Results | Show-ListView

Update:

You can prepare a result object based on provided input value during execution. for e.g

$inputValue = Show-Input "Please provide value 1 or 2" 
Write-Host "The value you've provided is '$($inputValue)'"

if ($inputValue -eq "1")
  { 
    $item = Get-Item -Path "master:\content\home\sample item 1"
      
    $Results = [pscustomobject]@{
    "Icon"=$Item.__Icon
    "DisplayName"=$Item.DisplayName
    "ItemPath"=$Item.ItemPath
    "Version"=$Item.Version
    "Language"=$Item.Language
    }

    $Results | Show-ListView
      
  }
elseif ($inputValue -eq "2")
  { 
   $item = Get-Item -Path "master:\content\home\sample item 1"

   $Results = [pscustomobject]@{
    "Icon"=$Item.__Icon
    "DisplayName"=$Item.DisplayName
    "ItemPath"=$Item.ItemPath
   }

   $Results | Show-ListView
  }

Hope it helps!

2
  • number of columns are not same every time it depends on the input provided during the execution
    – Vinesh
    Jun 19, 2023 at 10:00
  • Updated my answer, you can use conditions and prepare objects based on provided value. Jun 19, 2023 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.