locked
PowerShell: Return a list of language constructs RRS feed

  • Question

  • I am trying to return a list of all the PowerShell constructs like If, Do, ForEach-Object.  I tried using Get-Alias and Get-Command but neither of these will produce the desired results.  Anybody have a way of doing this?

    Cheers, Garth

    Wednesday, August 16, 2017 6:32 AM

Answers

  • Hi Garth,

    first of all, one thign you appear to have confused: 'ForEach-Object' is completely dissimilar to 'If' or 'Do': It's a cmdlet. The similarly named language component you probably meant was 'foreach'. Yes, there is a significant difference.

    I can't say I know where to get a full list - there's a help for most everything, but nothing like a comprehensive list that I know of. You can get a list of all types of elements in PowerShell however, if that is of a help. It includes all kinds of objects though:

    [enum]::GetNames([System.Management.Automation.Language.TokenKind])

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by NoneAndOne Thursday, August 17, 2017 7:57 AM
    Wednesday, August 16, 2017 7:16 AM

All replies

  • Hi Garth,

    first of all, one thign you appear to have confused: 'ForEach-Object' is completely dissimilar to 'If' or 'Do': It's a cmdlet. The similarly named language component you probably meant was 'foreach'. Yes, there is a significant difference.

    I can't say I know where to get a full list - there's a help for most everything, but nothing like a comprehensive list that I know of. You can get a list of all types of elements in PowerShell however, if that is of a help. It includes all kinds of objects though:

    [enum]::GetNames([System.Management.Automation.Language.TokenKind])

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by NoneAndOne Thursday, August 17, 2017 7:57 AM
    Wednesday, August 16, 2017 7:16 AM
  • http://ramblingcookiemonster.github.io/images/Cheat-Sheets/powershell-basic-cheat-sheet2.pdf
    Wednesday, August 16, 2017 10:08 AM
  • Also:

    help about_keywords


    \_(ツ)_/

    Wednesday, August 16, 2017 2:06 PM
  • Thanks Fred, that's fantastic!  You have introduced me to a newer and far more powerful PowerShell parser, I am going to have fun with this, much appreciated...
    Thursday, August 17, 2017 7:53 AM
  • Also:

    help about_keywords


    \_(ツ)_/

    yeah right...

    Thursday, August 17, 2017 7:56 AM
  • http://ramblingcookiemonster.github.io/images/Cheat-Sheets/powershell-basic-cheat-sheet2.pdf

    I want to return the info with a command.
    Thursday, August 17, 2017 7:56 AM
  • Hi Garth,

    first of all, one thign you appear to have confused: 'ForEach-Object' is completely dissimilar to 'If' or 'Do': It's a cmdlet. The similarly named language component you probably meant was 'foreach'. Yes, there is a significant difference.

    I can't say I know where to get a full list - there's a help for most everything, but nothing like a comprehensive list that I know of. You can get a list of all types of elements in PowerShell however, if that is of a help. It includes all kinds of objects though:

    [enum]::GetNames([System.Management.Automation.Language.TokenKind])

    Cheers,
    Fred


    There's no place like 127.0.0.1

    I should have mentioned, I got what I wanted using this command, thanks again Fred

         
    1
    2
    3
    4
    [enum]::GetNames([System.Management.Automation.Language.TokenKind]) | Sort |
        Where-Object {[System.Management.Automation.Language.TokenTraits]::HasTrait($_,"KeyWord")} |
        ForEach-Object{
            $_;

    • Edited by NoneAndOne Thursday, August 17, 2017 8:45 AM
    Thursday, August 17, 2017 8:43 AM
  • If you want to dump the full help file you could do this

    $keywords = get-help * 
    $myhelpfile = foreach ($keyword in $keywords)
    {
      get-help $keyword.name -full
      }
     $myhelpfile | out-file c:\test\help.txt

    Thursday, August 17, 2017 8:45 AM