Powershell String

Welcome Forums General PowerShell Q&A Powershell String

Viewing 3 reply threads
  • Author
    Posts
    • #254195
      Participant
      Topics: 1
      Replies: 1
      Points: 13
      Rank: Member

      I’m new to powershell, so bear with me.  I’m trying to do something I thought would be easy and common: find file paths that are “too long” (greater than some value. i.e. 260 character).   The below code runs fine, but while I can either output the file paths or and I can pipe to Select-Object and get the string length, I can’t figure out how to have them both. Get-Member shows $longpathfiles as  a ‘System.String’ type, with the only property being ‘Length’. What I want to end up with is a 2 column table.  ‘PathLength’, and ‘Path’ I can pipe to Out-Gridview or csv.  So….what am I missing?  Thanks in advance.

       

    • #254234
      Senior Moderator
      Topics: 9
      Replies: 1310
      Points: 4,789
      Helping Hand
      Rank: Community Hero

      Almost there… You just need to create a PSCustomObject foreach paths with the path name and length

    • #254285
      Participant
      Topics: 1
      Replies: 1
      Points: 13
      Rank: Member

      Thanks for the quick reply. This works great.

       

      But question though, why test against $NULL if I’m already filtering out anything with less than 260 character?

    • #254636
      Participant
      Topics: 0
      Replies: 81
      Points: 362
      Helping Hand
      Rank: Contributor

      You could have lines with 261 white spaces. if ($_.Trim()) should suffice though.

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