ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    People claim select-string is like grep...

    IT Discussion
    5
    7
    671
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • momurdaM
      momurda
      last edited by momurda

      Yet it cant look through output of a cmdlet like
      Get-SmbServerConfiguration
      0_1532382122738_50d20a66-48b3-401a-96d3-7de57ae335c0-image.png
      Seems ok so far
      Get-SmbServerConfiguration | select-string "Auto*"
      0_1532382272497_31fde333-5dae-49bc-a0cf-405b0e3e557a-image.png
      Clearly these should be returning something.

      However it does work for things like netstat
      0_1532382389868_001b04ef-451f-4f77-91da-43e1765c2858-image.png
      I could take Get-SmbServerConfiguration output to a text file then parse it, but why cant PS just read this?

      KellyK 1 Reply Last reply Reply Quote 3
      • black3dynamiteB
        black3dynamite
        last edited by black3dynamite

        Get-SmbServerConfiguration | Select-Object "Auto*"
        0_1532388189114_862f5dc7-7378-4419-9017-3e3a00dfb04f-image.png

        1 Reply Last reply Reply Quote 2
        • KellyK
          Kelly @momurda
          last edited by

          @momurda Have you tried using -Pattern with it? I.e. Get-SmbServerConfiguration | select-string -Pattern "Auto"

          black3dynamiteB 1 Reply Last reply Reply Quote 1
          • black3dynamiteB
            black3dynamite @Kelly
            last edited by

            @kelly said in People claim select-string is like grep...:

            @momurda Have you tried using -Pattern with it? I.e. Get-SmbServerConfiguration | select-string -Pattern "Auto"

            That didn't work when I tried it.

            1 Reply Last reply Reply Quote 1
            • momurdaM
              momurda
              last edited by

              @black3dynamite Oh i suppose that means the result of Get-SMBServerConfiguration is not string but a list of objects.

              scottalanmillerS D 2 Replies Last reply Reply Quote 1
              • scottalanmillerS
                scottalanmiller @momurda
                last edited by

                @momurda said in People claim select-string is like grep...:

                @black3dynamite Oh i suppose that means the result of Get-SMBServerConfiguration is not string but a list of objects.

                That's generally the case, and that's why PS is so complex and confusing. Bash uses straight text, always. So tools are universal and obvious. PS uses a mix of outputs and presents all as text but refuses to process them as such under certain cases. So you can't see what the output is, it takes extra steps to determine. It's not deterministic from an interface perspective making it confusing, complex, and to some degree risky because what should be obvious behaviour is not and things like filtering can yield inaccurately perceived results for this reason.

                1 Reply Last reply Reply Quote 1
                • D
                  Darek Hamann @momurda
                  last edited by

                  @momurda if you doubt what type (object/string/anything) is returned, try using $a.GetType() and it will return you the variable type.

                  1 Reply Last reply Reply Quote 2
                  • 1 / 1
                  • First post
                    Last post