Sitecore Powershell Extensions not returning field source value












1















I'm trying to write a simple Powershell script that finds all General Link fields and outputs the value of their Source field.



$fields = Get-ChildItem -Path "master://sitecore/templates/user defined" -Recurse | Where-Object { $_.TemplateName -eq "Template field" -and $_.Type -eq "General Link" }

foreach ($field in $fields) {
Write-Host "Name: $($field.Name)"
Write-Host "Source: $($field.Source)"
Write-Host
}


Whenever I run it, however, the value from the Source field is empty for all returned items.



Returned list of fields and empty sources



I've confirmed that it is populated in at least some of the cases, but it never shows up in the report. I've tried several variations to get the value, too:



$fields | Show-ListView -property `
@{ Name="Path"; Expression={$_.Paths.Path} },
@{ Name="Source"; Expression={$_.Source} },
@{ Name="Source With Quotes"; Expression={$_."Source"} }


Versions




  • Sitecore version: 8.1 Update 3

  • Sitecore PowerShell Extensions version: 5.0.0.42513










share|improve this question





























    1















    I'm trying to write a simple Powershell script that finds all General Link fields and outputs the value of their Source field.



    $fields = Get-ChildItem -Path "master://sitecore/templates/user defined" -Recurse | Where-Object { $_.TemplateName -eq "Template field" -and $_.Type -eq "General Link" }

    foreach ($field in $fields) {
    Write-Host "Name: $($field.Name)"
    Write-Host "Source: $($field.Source)"
    Write-Host
    }


    Whenever I run it, however, the value from the Source field is empty for all returned items.



    Returned list of fields and empty sources



    I've confirmed that it is populated in at least some of the cases, but it never shows up in the report. I've tried several variations to get the value, too:



    $fields | Show-ListView -property `
    @{ Name="Path"; Expression={$_.Paths.Path} },
    @{ Name="Source"; Expression={$_.Source} },
    @{ Name="Source With Quotes"; Expression={$_."Source"} }


    Versions




    • Sitecore version: 8.1 Update 3

    • Sitecore PowerShell Extensions version: 5.0.0.42513










    share|improve this question



























      1












      1








      1








      I'm trying to write a simple Powershell script that finds all General Link fields and outputs the value of their Source field.



      $fields = Get-ChildItem -Path "master://sitecore/templates/user defined" -Recurse | Where-Object { $_.TemplateName -eq "Template field" -and $_.Type -eq "General Link" }

      foreach ($field in $fields) {
      Write-Host "Name: $($field.Name)"
      Write-Host "Source: $($field.Source)"
      Write-Host
      }


      Whenever I run it, however, the value from the Source field is empty for all returned items.



      Returned list of fields and empty sources



      I've confirmed that it is populated in at least some of the cases, but it never shows up in the report. I've tried several variations to get the value, too:



      $fields | Show-ListView -property `
      @{ Name="Path"; Expression={$_.Paths.Path} },
      @{ Name="Source"; Expression={$_.Source} },
      @{ Name="Source With Quotes"; Expression={$_."Source"} }


      Versions




      • Sitecore version: 8.1 Update 3

      • Sitecore PowerShell Extensions version: 5.0.0.42513










      share|improve this question
















      I'm trying to write a simple Powershell script that finds all General Link fields and outputs the value of their Source field.



      $fields = Get-ChildItem -Path "master://sitecore/templates/user defined" -Recurse | Where-Object { $_.TemplateName -eq "Template field" -and $_.Type -eq "General Link" }

      foreach ($field in $fields) {
      Write-Host "Name: $($field.Name)"
      Write-Host "Source: $($field.Source)"
      Write-Host
      }


      Whenever I run it, however, the value from the Source field is empty for all returned items.



      Returned list of fields and empty sources



      I've confirmed that it is populated in at least some of the cases, but it never shows up in the report. I've tried several variations to get the value, too:



      $fields | Show-ListView -property `
      @{ Name="Path"; Expression={$_.Paths.Path} },
      @{ Name="Source"; Expression={$_.Source} },
      @{ Name="Source With Quotes"; Expression={$_."Source"} }


      Versions




      • Sitecore version: 8.1 Update 3

      • Sitecore PowerShell Extensions version: 5.0.0.42513







      powershell-extensions






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 15 at 16:57







      Dan Sinclair

















      asked Feb 15 at 15:06









      Dan SinclairDan Sinclair

      1,954525




      1,954525






















          2 Answers
          2






          active

          oldest

          votes


















          5














          There is no Source property on Sitecore.Data.Items.Item class.



          You need to get Source field value e.g. like this:



          foreach ($field in $fields) {
          Write-Host "Name: $($field.Name)"
          Write-Host "Source: $($field._.Source.Value)"
          Write-Host
          }





          share|improve this answer



















          • 1





            This example is making use of a custom object SPE adds to the item. You can use _ or PSFields to get typed properties.

            – Michael West
            Feb 15 at 16:25



















          2














          The issue is that the Source field is of type Template Field Source, which seems to not automatically emit a value if you simply access the field directly on the item ($field.Source).



          Instead, you must get the field and get the value from that field:



          $field.Fields['Source'].Value





          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "664"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f16819%2fsitecore-powershell-extensions-not-returning-field-source-value%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            5














            There is no Source property on Sitecore.Data.Items.Item class.



            You need to get Source field value e.g. like this:



            foreach ($field in $fields) {
            Write-Host "Name: $($field.Name)"
            Write-Host "Source: $($field._.Source.Value)"
            Write-Host
            }





            share|improve this answer



















            • 1





              This example is making use of a custom object SPE adds to the item. You can use _ or PSFields to get typed properties.

              – Michael West
              Feb 15 at 16:25
















            5














            There is no Source property on Sitecore.Data.Items.Item class.



            You need to get Source field value e.g. like this:



            foreach ($field in $fields) {
            Write-Host "Name: $($field.Name)"
            Write-Host "Source: $($field._.Source.Value)"
            Write-Host
            }





            share|improve this answer



















            • 1





              This example is making use of a custom object SPE adds to the item. You can use _ or PSFields to get typed properties.

              – Michael West
              Feb 15 at 16:25














            5












            5








            5







            There is no Source property on Sitecore.Data.Items.Item class.



            You need to get Source field value e.g. like this:



            foreach ($field in $fields) {
            Write-Host "Name: $($field.Name)"
            Write-Host "Source: $($field._.Source.Value)"
            Write-Host
            }





            share|improve this answer













            There is no Source property on Sitecore.Data.Items.Item class.



            You need to get Source field value e.g. like this:



            foreach ($field in $fields) {
            Write-Host "Name: $($field.Name)"
            Write-Host "Source: $($field._.Source.Value)"
            Write-Host
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 15 at 15:26









            Marek MusielakMarek Musielak

            10.4k11136




            10.4k11136








            • 1





              This example is making use of a custom object SPE adds to the item. You can use _ or PSFields to get typed properties.

              – Michael West
              Feb 15 at 16:25














            • 1





              This example is making use of a custom object SPE adds to the item. You can use _ or PSFields to get typed properties.

              – Michael West
              Feb 15 at 16:25








            1




            1





            This example is making use of a custom object SPE adds to the item. You can use _ or PSFields to get typed properties.

            – Michael West
            Feb 15 at 16:25





            This example is making use of a custom object SPE adds to the item. You can use _ or PSFields to get typed properties.

            – Michael West
            Feb 15 at 16:25











            2














            The issue is that the Source field is of type Template Field Source, which seems to not automatically emit a value if you simply access the field directly on the item ($field.Source).



            Instead, you must get the field and get the value from that field:



            $field.Fields['Source'].Value





            share|improve this answer




























              2














              The issue is that the Source field is of type Template Field Source, which seems to not automatically emit a value if you simply access the field directly on the item ($field.Source).



              Instead, you must get the field and get the value from that field:



              $field.Fields['Source'].Value





              share|improve this answer


























                2












                2








                2







                The issue is that the Source field is of type Template Field Source, which seems to not automatically emit a value if you simply access the field directly on the item ($field.Source).



                Instead, you must get the field and get the value from that field:



                $field.Fields['Source'].Value





                share|improve this answer













                The issue is that the Source field is of type Template Field Source, which seems to not automatically emit a value if you simply access the field directly on the item ($field.Source).



                Instead, you must get the field and get the value from that field:



                $field.Fields['Source'].Value






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 15 at 15:18









                Dan SinclairDan Sinclair

                1,954525




                1,954525






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Sitecore Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f16819%2fsitecore-powershell-extensions-not-returning-field-source-value%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

                    How to change which sound is reproduced for terminal bell?

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?