1

We would like to show custom data such as custom string(" Test Case 1","Test case 2"). All these data do not inside any items in Sitecore. It is just a string in powershell script and would like to show in Show-ListView.

We would like to add one column inside Show-ListView and show data under this column.

Is this possible? Kindly assist someone on this.

2
  • Have you reviewed the documentation? What have you tried? Commented Sep 28, 2021 at 5:52
  • Yes I have reviewed the document and I have tried with property and ViewName
    – Ashish
    Commented Sep 28, 2021 at 8:09

1 Answer 1

4

1. Using PSCustomObject in array

$list = [System.Collections.ArrayList]@()

in for each loop assign value to info object and then add it to list

$info = [PSCustomObject]@{
                            "data1"="test 1"
                            "data2" = "test data 2"
                        }
                    [void]$list.Add($info)

then show it finally

$list | Show-ListView

2. Using Class, example given below:

class Topics {
    [string]$TopicId
    [string]$TopicPath
    [string]$TopicName
}

create its array object

[Topics[]]$AllTopics = @()

assign values to it

$topicfolders|get-childitem |foreach-object{
    $topic=       [Topics]@{
           TopicId =  $_.Id
           TopicPath= $_.fullpath
           TopicName =  $_.name
        
    }
            $AllTopics =[Array] $AllTopics +  $topic
}
#then show $AllTopics 

3. Directly assign value to psobject and show that

$customItem = [pscustomobject]@{
    "ID"=$Item.ID
    "Icon"=$Item.__Icon
    "DisplayName"=$Item.DisplayName
    "ItemPath"=$Item.ItemPath
    "Version"=$Item.Version
    "Language"=$Item.Language
    "__Updated"=$Item.__Updated
    "__Updated by"=$Item."__Updated by"
}

$customItem | Show-ListView

4.using Expression of show-listview, either give your value in it or create a function and use that to get values.

2
  • I have resolved it by adding [PSCustomObject]. Only change is here $info = [PSCustomObject]@{ data1="test 1" data2 = "test data 2" } $info | Show-ListView
    – Ashish
    Commented Sep 28, 2021 at 9:58
  • Great, please accept comment as answer if that helped.
    – Rinku Jain
    Commented Sep 28, 2021 at 14:43

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.