Not able to fill empty array with data from function

Welcome Forums General PowerShell Q&A Not able to fill empty array with data from function

  • This topic has 4 replies, 2 voices, and was last updated 1 month ago by
    Participant
    .
Viewing 4 reply threads
  • Author
    Posts
    • #251747
      Participant
      Topics: 10
      Replies: 31
      Points: 82
      Rank: Member

      Hi folks. i’m using Powershell to extract data values from sharepoint on-prem and into an empty array. So far it does not seem to work. Only when i use Write-Host, the output window shows the data i need. But $hashtable does not seem to capture any of the data i’m trying to pull. $hashtable.count is empty. What am i missing? Thank you

      • This topic was modified 1 month ago by Mahin.
      • This topic was modified 1 month ago by Mahin.
    • #251759
      Participant
      Topics: 15
      Replies: 1775
      Points: 3,214
      Helping Hand
      Rank: Community Hero

      Do not have SharePoint to test, but you have the hashtable variable defined outside the function, so you should be getting errors about op_addition in the function. Try setting a variable to the foreach and you do not need the += operation. Also, if you want output inside the function, use Write-Verbose. Here is something to try:

    • #251918
      Participant
      Topics: 10
      Replies: 31
      Points: 82
      Rank: Member

      Thanks so much Rob, you are a genius! From my original post, i have the bottom code to call the function. When i execute the entire set of code, it looks perfect in ISE output window, but i’m trying to Export to CSV the value of Write-Host “$($web.URL)” along with the $file.name and $file.URL.

      The $web.URL, is the first portion of the full Sharepoint website URL. $file.URL is the second portion of the full Sharepoint URL.

      Currently i have the Export-CSV cmdlet after Get-SPFiles($List.RootFolder) but it does not include the 1st critical value of $($web.URL), it only exports the $file.name and $file.URL. Hope my explanation is not too convoluted 🙂 Thank you again

       

    • #251921
      Participant
      Topics: 15
      Replies: 1775
      Points: 3,214
      Helping Hand
      Rank: Community Hero

      Try something like this:

    • #251924
      Participant
      Topics: 10
      Replies: 31
      Points: 82
      Rank: Member

      Thanks Rob! piping out the $results gives me all 3 values we needed. Much appreciated sir.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.